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

如何在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条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料