Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save t-kuni/1ecec9d185aac837457ad9e583af53fb to your computer and use it in GitHub Desktop.
Save t-kuni/1ecec9d185aac837457ad9e583af53fb to your computer and use it in GitHub Desktop.
Go + delve + airな環境でリモートデバッグを行う

Go + delve + airな環境でリモートデバッグを行う

Goのコンテナにdelveをインストール

例えばDockerfileに以下を追記する

go install github.com/go-delve/delve/cmd/dlv@latest

コンテナ起動時にポート2345を開放する

airの設定ファイルを作成する

ルートフォルダに.air.tomlを作成します

root = "."
tmp_dir = "tmp"

[build]
cmd = 'go build -gcflags "all=-N -l" -o ./tmp/main'
full_bin = "dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec --continue tmp/main"

各項目の意味はこちらを参照

GoLnadの設定

以下のように実行設定を作成する

image

以下のボタンでデバッグが開始できる

image

vscodeの設定

以下ページのstep1の4まで進める(Goのプラグインと各種ツールをインストールする)

https://future-architect.github.io/articles/20201117/

.vscode/launch.jsonを作成する remotePathはよしなに書き換えて下さい

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Connect to server",
            "type": "go",
            "request": "attach",
            "mode": "remote",
            "remotePath": "[プロジェクトのルートディレクトリ]",
            "port": 2345,
            "host": "127.0.0.1"
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment