air-verse / air

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

Does it support start multiple go files for microservices project? #57

Open WLun001 opened 4 years ago

WLun001 commented 4 years ago

Assuming the folder structure look like this

.
|--- api 
|       |--- main.go
|---svr 
.      |--- service1
           |--- main.go
       |--- service 2
          |--- main.go
cosmtrek commented 4 years ago

Yes

WLun001 commented 4 years ago

Could you please provide me example?

cosmtrek commented 4 years ago

Oops, I misunderstood. Currently, It does not support running multiple binaries at the same time.

rodneysantos commented 2 years ago

I'm also wondering if this is possible. For now, I've created multiple .air.toml files that reside within each microservice directory and then run ./air -c ./api/.air.toml and ./air -c ./svr/service1/.air.toml.

I don't know if there's any better way than this, but I'll leave this here for those looking for a workaround/solution.

|--- api
        |--- main.go
        |--- .air.toml
|---svr 
       |--- service1
           |--- main.go
           |--- .air.toml
       |--- service 2
Marv963 commented 2 months ago

I solved this issue by defining services in the Makefile and using a conditional command in my .air.toml. Here’s how I did it:

In the Makefile, I defined the services:

service1:
    cd go-microservices && \
    export APP_NAME=service1 && \
    air

service2:
    cd go-microservices && \
    export APP_NAME=service2 && \
    air

In my .air.toml, I set the cmd as follows:

cmd = """ 
echo "Starting $APP_NAME ...";
case "$APP_NAME" in
  "service1")
    go build -tags=dev -o ./tmp/main ./cmd/scraper/service1/
    ;;
  "service2")
    go build -tags=dev -o ./tmp/main ./cmd/scraper/service2/
    ;;
  *)
    echo "Unknown APP_NAME: $APP_NAME"
    exit 1
    ;;
esac
"""

This approach allows me to dynamically set the service to build and run based on the APP_NAME environment variable.