Open WLun001 opened 4 years ago
Yes
Could you please provide me example?
Oops, I misunderstood. Currently, It does not support running multiple binaries at the same time.
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
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.
Assuming the folder structure look like this