英文:
why does os.Getenv("SERVER_SOFTWARE") returns blank string for me?
问题
我最近升级到最新版本的Go SDK(1.8.0),现在当我调用os.Getenv("SERVER_SOFTWARE")时,我得到一个空字符串。我使用这个来确定我是在本地开发服务器还是生产环境中,我不知道还有其他的检查方式。所以对于这两个问题的任何一个答案都可以:1)为什么现在返回一个空字符串?或者2)是否有其他的方法来检查我是否在开发服务器上?
英文:
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?
答案1
得分: 0
使用os.Environ
函数查看开发服务器设置的环境变量。查看其中是否有用于区分开发和生产服务器的候选变量。例如,APPLICATION_ID
环境变量。
> Go开发服务器
>
> 在开发Web服务器中访问应用程序ID
>
> 开发服务器模拟生产App Engine服务。
> 其中一种方式是在APPLICATION_ID
环境变量前面添加一个字符串(dev~
)。
英文:
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.
> The Go Development Server
>
> Accessing Application IDs in the Development Web Server
>
> 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.
答案2
得分: 0
所以...最近我发现了很多“嘿,我很笨,有更好的方法”的答案来回答我的问题。这似乎就是其中之一。所以如果我退一步,解决我试图回答的真正问题,一切就变得简单多了。我只是想找到一种方法来确定我是在开发服务器还是在生产服务器上。我正在研究一个完全无关的问题,然后发现了这个:appengine.IsDevAppServer()。它有完整的文档:https://developers.google.com/appengine/docs/go/reference#IsDevAppServer,只是我直到现在才看到它。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论