如何在 app.yaml 中为 Go 传递 运行 参数?

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

根据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.

我该如何配置?在任何地方都找不到详细信息。 我可以这样做吗?

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

我没有云构建文件,只有 app.yaml。那么 entrypoint 到底有什么作用呢? 当 App Engine 到达 入口点 部分时,程序是否已经编译?

谢谢

我刚才用我自己的 GCP AppEngine 项目尝试了这个,但使用 entrypoint(例如 entrypoint: go run ./cmd/web prod)对我不起作用。当我尝试它时,我收到了这个神秘的错误消息:

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

我正在使用 Google Cloud SDK 344.0.0

虽然我只是想将 args 传递到我的 golang main 中,但我的情况与您类似。在 the docs 之后,我改用 env_variables 来代替它。

我的 app.yaml 看起来像:

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

然后在我的代码中,我只需在任何地方使用 os.Getenv("APP_ENV") 即可访问。