简体   繁体   English

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

[英]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.通过在应用启动时执行 entrypoint 命令来覆盖默认启动行为。 For your app to receive HTTP requests, the entrypoint element should contain a command which starts a web server that listens on port 8080.为了让您的应用程序接收 HTTP 请求,入口点元素应包含一个命令,该命令启动一个侦听端口 8080 的 web 服务器。

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.我没有云构建文件,只有 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.我刚刚用我自己的 GCP AppEngine 项目尝试了这个,并且使用entrypoint点(例如entrypoint: go run./cmd/web prod )对我不起作用。 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 .我正在使用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.我的情况与您类似,但我只是想将args传递到我的 golang main 中。 Following the docs , I changed over to using env_variables instead which worked.docs之后,我改用env_variables代替它工作。

My app.yaml looks like:我的 app.yaml 看起来像:

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.然后在我的代码中,我只需在任何地方使用os.Getenv("APP_ENV")即可访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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