英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论