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

标签 go google-app-engine google-app-engine-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。那么是什么入口点 真的吗?
当应用引擎到达 入口点 部分程序是否已经编译?
谢谢

最佳答案

我刚刚在我自己的 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")任何地方都可以访问。

关于go - 如何在 app.yaml 中为 Go 传递运行参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67843806/

相关文章:

php - http 将 url 部分路由到不同的服务器

go - 将结构放入 slice 时出现 golang 错误

go - 我们如何创建一个空 map 并在 golang 中附加新数据?

java - 无法删除 blob - GAE Java

google-app-engine - 跨多个应用程序版本的数据转换

google-app-engine - 如何使我的 GAE 系统安全

go - 覆盖 http.FileServer 中的 Last-Modified header

google-app-engine - 如何在与 app.yaml 不同的文件夹中为 appengine Go 使用主包?

google-app-engine - 如何 fmt.Println() 内存不是由 go 程序分配的?

google-app-engine - 为什么 GAE 标准环境中没有 Cloud Endpoints for Golang?