An example of using Air (for live reload), Delve (for debugging), and Cobra (for CLI commands) together in Docker for local development.
This is intended as a simple example of getting the two tools working together.
For this example, the entry point in the Dockerfile is air
CMD ["air", "-c", ".air.toml"]
On first run and reload, Air builds the new executable.
go build -o ./.dev/main .
Then Air uses Delve to run the Cobra Cmd
dlv exec ... ./.dev/main serve
To see it in action, you can run docker compose up -d from the root directory.
After that, any edit you make to main.go will trigger a reload. You can test it by changing the message in indexHandler to a different string.
To configure debugging in Goland, you'll want to follow the steps outlined in Attach to a process on a remote machine
- cosmtrek/air: ☁️ Live reload for Go apps
- go-delve/delve: Debugger for the Go programming language.
- spf13/cobra: Library for creating powerful modern CLI applications.