doudengshen5591 2015-05-25 06:09
浏览 383
已采纳

如何在Go中检测操作系统版本?

I'm currently writing a REST API client, and I'm trying to determine what OS the user is using in order to generate a useful User Agent string. This is going to allow me to (hopefully) make good decisions about what OS's I should bother supporting in the future.

What I'd like to do is this: generate a string that looks something like:

Linux/1.3.2 OR Darwin/1.3.2 OR Windows/1.3.2

It should work across Linux / Mac / Windows.

Currently, I'm able to retrieve the OS type (eg: 'linux' / 'windows' / 'darwin') using

runtime.GOOS

But I'm unable to find a way to grab the OS major/minor/micro versions.

  • 写回答

2条回答 默认 最新

  • dongyue4964 2015-05-25 06:19
    关注

    Based on the extensive discussion in Go google group it looks like nothing reliable exists. I still suggest you to take a look at the discussion, as there are some useful ideas how to extract some information for particular OS.

    P.S. does not the browser send this information in User_Agent?

    User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?