How to Debug Google App Engine for Golang with VS Code

Summary

Basic

see Golang

Spec

see Golang

Instruction

$ln -s go ~/google-cloud-sdk/platform/google_appengine/goroot-1.9/goapp
{
  "go.goroot": "~/google-cloud-sdk/platform/google_appengine/goroot-1.9",
  "go.gopath": "~/google-cloud-sdk/platform/google_appengine/gopath",
  "go.toolsGopath": "~/google-cloud-sdk/platform/google_appengine/gopath"
}

when failing install some packages (ex: delve, godoc)

$~/google-cloud-sdk/platform/google_appengine/goroot-1.9/bin/goapp version
go version 1.9.4 (appengine-1.9.71) darwin/amd64
$export GOPATH=~/google-cloud-sdk/platform/google_appengine/gopath
$export GOROOT=go1.9.4
$go1.9.4/bin/go get github.com/derekparker/delve/cmd/dlv
$go1.9.4/bin/go get golang.org/x/tools/cmd/godoc

prefer setting

set direnv settings(.envrc) in the workspace

export GOROOT=~/google-cloud-sdk/platform/google_appengine/goroot-1.9/
export GOPATH=~/google-cloud-sdk/platform/google_appengine/gopath/
export PATH=~/google-cloud-sdk/platform/google_appengine/gopath/bin:$PATH
export PATH=~/google-cloud-sdk/platform/google_appengine/goroot-1.9/bin:$PATH

debugging devserver

settings.json

same for remote debugging

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

how to

$dev_appserver.py app.yaml --go_debugging
$ps au | grep _go_ap[p]
nnyn 16353   0.0  0.0 558439268   4384 s002  S+    5:54PM   0:00.01 /var/folders/tb/nzm_jqzn1f5d1r2jlj8jp3nw0000gn/T/tmputIGVHappengine-go-bin/_go_app
$dlv attach 16353 --headless --listen=:2345 --log
API server listening at: [::]:2345