为什么os.Getenv(“SERVER_SOFTWARE”)为我返回空字符串?

时间:2021-01-01 23:06:21

I recently upgraded to the latest version of the Go SDK (1.8.0), and now when I call os.Getenv("SERVER_SOFTWARE") I get a blank string. I am using this to determine if I am on my local development server or the live environment, and I am not aware of any other way to check. So an answer to either question would suite me just fine: 1) Why is that returning a blank string now? or 2) Is there some other way to check if I'm on the dev server?

我最近升级到最新版本的Go SDK(1.8.0),现在当我调用os.Getenv(“SERVER_SOFTWARE”)时,我得到一个空字符串。我使用它来确定我是否在我的本地开发服务器或实时环境中,并且我不知道有任何其他方法可以检查。所以对这两个问题的回答都很合适:1)为什么现在返回一个空白字符串?或2)是否有其他方法来检查我是否在开发服务器上?

2 个解决方案

#1


0  

Use the os.Environ function to see what environment variables are set for the development server. See if any of them are candidates for distinguishing between the development and production servers. For example, the APPLICATION_ID environment variable.

使用os.Environ函数查看为开发服务器设置的环境变量。看看它们中是否有任何一个可以区分开发和生产服务器。例如,APPLICATION_ID环境变量。

The Go Development Server

Go开发服务器

Accessing Application IDs in the Development Web Server

在Development Web Server中访问应用程序ID

The development server simulates the production App Engine service. One way in which it does this is to prepend a string (dev~) to the APPLICATION_ID environment variable.

开发服务器模拟生产App Engine服务。执行此操作的一种方法是在APPLICATION_ID环境变量中添加字符串(dev~)。

#2


0  

So... I've been finding lots of "hey, I'm dumb and there's a better way" answers to my questions lately. This seems to be one of those. So if I back up a step, and address the real question that I'm trying to answer, everything becomes much simpler. I'm just trying to have a way to determine if I'm on the dev server or the live server. I was researching a totally unrelated problem, and found this: appengine.IsDevAppServer(). It's fully documented: https://developers.google.com/appengine/docs/go/reference#IsDevAppServer, I just never saw it until now.

所以...我一直在找到很多“嘿,我愚蠢而且有更好的方法”最近回答了我的问题。这似乎就是其中之一。因此,如果我支持一步,并解决我想要回答的真正问题,一切都变得简单得多。我只是试图确定我是在开发服务器还是在线服务器上。我正在研究一个完全不相关的问题,并发现了这个:appengine.IsDevAppServer()。它已完整记录:https://developers.google.com/appengine/docs/go/reference#IsDevAppServer,我直到现在才看到它。

#1


0  

Use the os.Environ function to see what environment variables are set for the development server. See if any of them are candidates for distinguishing between the development and production servers. For example, the APPLICATION_ID environment variable.

使用os.Environ函数查看为开发服务器设置的环境变量。看看它们中是否有任何一个可以区分开发和生产服务器。例如,APPLICATION_ID环境变量。

The Go Development Server

Go开发服务器

Accessing Application IDs in the Development Web Server

在Development Web Server中访问应用程序ID

The development server simulates the production App Engine service. One way in which it does this is to prepend a string (dev~) to the APPLICATION_ID environment variable.

开发服务器模拟生产App Engine服务。执行此操作的一种方法是在APPLICATION_ID环境变量中添加字符串(dev~)。

#2


0  

So... I've been finding lots of "hey, I'm dumb and there's a better way" answers to my questions lately. This seems to be one of those. So if I back up a step, and address the real question that I'm trying to answer, everything becomes much simpler. I'm just trying to have a way to determine if I'm on the dev server or the live server. I was researching a totally unrelated problem, and found this: appengine.IsDevAppServer(). It's fully documented: https://developers.google.com/appengine/docs/go/reference#IsDevAppServer, I just never saw it until now.

所以...我一直在找到很多“嘿,我愚蠢而且有更好的方法”最近回答了我的问题。这似乎就是其中之一。因此,如果我支持一步,并解决我想要回答的真正问题,一切都变得简单得多。我只是试图确定我是在开发服务器还是在线服务器上。我正在研究一个完全不相关的问题,并发现了这个:appengine.IsDevAppServer()。它已完整记录:https://developers.google.com/appengine/docs/go/reference#IsDevAppServer,我直到现在才看到它。