有没有办法检测代码是在本地运行、测试环境还是在App Engine上运行?

huangapple go评论87阅读模式
英文:

Is there a way to detect whether the code is run on local, test environment or on App Engine?

问题

我正在开发一个使用Google App Engine Go的应用程序,并在本地进行测试。我有一些用于测试环境的变量,还有一些用于实际的App Engine环境的变量。我想知道是否有一种方法可以从代码内部确定代码运行的环境,并且在不需要一直注释和取消注释代码的情况下使用正确版本的变量。

英文:

I am developing a Google App Engine Go application and testing it locally. I have some variables for test environment and some variables for the live App Engine environment. I am wondering whether there is some way to determine from inside the code what environment the code is run in and use a proper version of the variable without having to comment and uncomment code all the time.

答案1

得分: 8

你是否阅读了有关运行时环境的文档?

它指向了这个文档https://developers.google.com/appengine/docs/go/reference,其中列出了一系列可以提供有关运行时环境信息的函数。

具体来说,

 func IsDevAppServer() bool
英文:

Have you read the docs on the runtime environemnt.

It points to this document https://developers.google.com/appengine/docs/go/reference which lists a bunch of functions that give you information about the runtime environemnt.

Specifically

 func IsDevAppServer() bool

huangapple
  • 本文由 发表于 2014年5月22日 05:26:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/23794103.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定