Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running on the root folder doesn't work #539

Open
noloman opened this issue Feb 28, 2024 · 2 comments
Open

Running on the root folder doesn't work #539

noloman opened this issue Feb 28, 2024 · 2 comments

Comments

@noloman
Copy link

noloman commented Feb 28, 2024

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
  • 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!

@leandergangso
Copy link

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
Copy link

chtx commented Apr 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants