简体   繁体   中英

How to pass run arguments in app.yaml for Go?

According to Docs :

entrypoint
Optional. Overrides the default startup behavior by executing the entrypoint command when your app starts. For your app to receive HTTP requests, the entrypoint element should contain a command which starts a web server that listens on port 8080.

How would I configure this? there are no details found anywhere. Can I do this?

entrypoint: go run main.go fooArg --bar-flag=1

I don't have cloud build file, only app.yaml. so what does entrypoint really do? when app engine reaches entrypoint part is the program already compiled?

Thank you

I tried this just now with my own GCP AppEngine project and using entrypoint (eg. entrypoint: go run./cmd/web prod ) did not work for me. When I tried it, I am getting this cryptic error message:

Error type: UNKNOWN
Error message: no Go files in /layers/google.go.appengine_gomod/srv

I'm using Google Cloud SDK 344.0.0 .

I'm in a similar situation like you though where I'm simply trying to pass in args into my golang main. Following the docs , I changed over to using env_variables instead which worked.

My app.yaml looks like:

runtime: go115
main: ./cmd/web
env_variables:
  APP_ENV: "prod"

and then in my code, I simply use os.Getenv("APP_ENV") anywhere to access.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM