air
air copied to clipboard
Running on the root folder doesn't work
Hi,
I'm not sure how to properly run air in my project:
I have a root folder which contains the following folders:
- cmd
- api
- internal
- data
- validator
- data
- migrations
Without air, I'd normally run my project with go run /cmd/api
.
If I run air init
in the root folder, I always get:
mkdir /Users/MyUser/Developer/MyProject/tmp
watching .
watching bin
watching cmd
watching cmd/api
watching cmd/tmp
watching internal
watching internal/data
watching internal/data/validator
watching migrations
!exclude tmp
building...
no Go files in /Users/MyUser/Developer/MyProject
failed to build, error: exit status 1
running...
/bin/sh: /Users/MyUser/Developer/MyProject: is a directory
Process Exit with Code: 126
However, if I run it into the /cmd/api
which is where my main.go
file is, it works fine EXCEPT that if I modify any file outside of /cmd/api
, then air doesn't pick up those changes.
How can I properly set up and run air so that it monitors all my changes?
Thanks!
You probably figured it out, but you most likely just have to configure the air.toml (in root dir) to run go build -o temp/main cmd/api/main.go
instead of what's the default.
And if you have multiple go files in the directory, point it to the entire directory, not just the main.go file, i.e. go build -o ./tmp/main ./cmd/api
. @cosmtrek I think this should be included in the FAQ section, under "What to do if my go files are not in the root directory?". I have spent a good amount of time trying to figure it out because I'm a total newbie. I bet there will be more people looking for that in the future. Thanks.