LoginSignup
0
0

More than 5 years have passed since last update.

Google App Engine で始める Go 実践入門 Part 7 【リモートデバッグ】

Last updated at Posted at 2019-03-31

連載を通して簡単なブログアプリを作成しつつ Go/GAE について学んでいきます。
今回は リモートデバッグ についての説明です。

リモートデバッグ

VS Code と App Engine ローカル開発サーバーでリモートデバッグができるようにします。

ポイントは次の通りです。

  • VS Code でデバッグ用の設定ファイルを作る
  • サーバー起動時に --go_debugging=True をオプションで渡す
  • Go の Debugger である delve をインストールする (インストール済み)
  • delve コマンドを用いて Debugger をサーバーにアタッチする

まずは VS Code のデバッグ用設定ファイルを作成します。

touch .vscode/launch.json
.vscode/launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Connect to server",
      "type": "go",
      "request": "launch",
      "mode": "remote",
      "remotePath": "${workspaceFolder}",
      "port": 2345,
      "host": "127.0.0.1",
      "program": "${workspaceFolder}",
      "env": {},
      "args": []
    }
  ]
}

次にサーバーを起動します。

dev_appserver.py module/blog/main/app.yaml --support_datastore_emulator=False --go_debugging=True

サーバーが起動したらターミナルをもう 1 枚開いて Debugger をアタッチします。
VS Code であればターミナルの分割 (Command + Alt + Ctrl + \) を使うのが便利です。

dlv attach $(ps u | grep _go_ap[p] | head -1 | awk '{print $2}') --headless --listen=127.0.0.1:2345 --api-version=2

次に VS Code 上でブレークポイントを設置します。

デバッグを開始 (F5) します。

この状態でブラウザから localhost:8080 にアクセスすると、ブレークポイントでプログラムがストップします。

スクリーンショット 2019-03-24 12.10.48.png

ローカル開発用サーバーのオプション | Google Cloud

おわりに

次回のテーマは『デプロイ』です。

よかったら Twitter フォローしてね。@_rema424

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0