Go Debugging
01 Dec 2023 - Daniel Ramirez
Description of options for debugging standalone go program (not a web server).
VSCode In-IDE Debugger
def foo
puts 'foo'
end
- have launch.json
{ "name": "Launch Package", "type": "go", "request": "launch", "mode": "auto", "program": "${fileDirname}", "console": "integratedTerminal", "showGlobalVariables": true },
- hit Launch
- Interact with program inside of xterm.js
Other considerations
bubbletea
- Insert logToFile somewhere near entry point to program
if len(os.Getenv("DEBUG")) > 0 { f, err := tea.LogToFile("debug.log", "debug") if err != nil { fmt.Println("fatal:", err) os.Exit(1) } defer f.Close() }
- Add logging wrapped in
DEBUG
checksif len(os.Getenv("DEBUG")) > 0 { log.Println(foo) }