有没有一种方法可以检测代码是在本地,测试环境还是在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.

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