I'm very new to Go and I just followed the air guide to getting my app live-reloading, which worked, but when I then tried to move my Go files to subdirectories to follow the advice in the "Let's Go Further" ebook, air stopped working.
I eventually figured it out with a lot of Googling:
cmd
parameter in my .air.toml
file to point at the directory where I had moved my main.go
file:cmd = "go build -o ./tmp/main ./cmd/api/."
.air.toml
file to list the directories I wanted it to watch for changes:include_dir = ["cmd", "internal"]
./
in the directory names, that tripped me up for a while.So my backend
directory now looks like this:
bin/
cmd/
api/
internal/
data/
migrations/
remote/
.air.toml
.gitignore
go.mod
Makefile
And my .air.toml
now looks like this:
[build]
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ./cmd/api/."
include_dir = ["cmd", "internal"]
log = "stdout"
[run]
cmd = "./tmp/main" # Command to run the binary