air-verse / air

☁️ Live reload for Go apps
GNU General Public License v3.0
16.35k stars 771 forks source link

Running on the root folder doesn't work #539

Open noloman opened 4 months ago

noloman commented 4 months ago

Hi,

I'm not sure how to properly run air in my project:

I have a root folder which contains the following folders:

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!

leandergangso commented 4 months ago

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.

chtx commented 3 months ago

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.