I want to set global variable, for example:
var DEBUG_MODE bool
func init() {
// set DEBUG_MODE true if localhost (not appspot.com or other domain)
}
How to do this?
I want to set global variable, for example:
var DEBUG_MODE bool
func init() {
// set DEBUG_MODE true if localhost (not appspot.com or other domain)
}
How to do this?
Easiest is to use use
appengine.IsDevAppServer()
to tell if your app is running in development mode (using the AppEngine SDK) or live (in production):Alternatively you can also use
appengine.ServerSoftware()
which contains this information along with your App version, merged into one string:So for example what you want to do:
Or in one line:
Although note that you could just call
appengine.IsDevAppServer()
whenever you would refer toDEBUG_MODE
. Also the nameDEBUG_MODE
does not conform to Go naming conventions, it should either beDebugMode
if it needs to be exported (because you want to access it from other packages too), or it should bedebugMode
if it doesn't need to be exported.See this related question (possible duplicate?): How to set variables based on project id?