例えばDockerfileに以下を追記する
go install github.com/go-delve/delve/cmd/dlv@latest
コンテナ起動時にポート2345
を開放する
ルートフォルダに.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"
各項目の意味はこちらを参照
以下のように実行設定を作成する
以下のボタンでデバッグが開始できる
以下ページの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"
}
]
}