如何在Go中获取系统信息?

时间:2015-05-07 06:42:08

标签: go

有人可以推荐一个可以用来获取系统信息的模块,比如Python的psutil吗?

当我尝试>go get github.com/golang/sys get 'sys'时,我收到了以下内容:

Report Error:
package github.com/golang/sys
        imports github.com/golang/sys
        imports github.com/golang/sys: no buildable Go source files in D:\go_source\src\github.com\golang\sys

这是我的系统环境:

# native compiler windows amd64

GOROOT=D:\Go
#GOBIN=
GOARCH=amd64
GOOS=windows
CGO_ENABLED=1

PATH=c:\mingw64\bin;%GOROOT%\bin;%PATH%

LITEIDE_GDB=gdb64
LITEIDE_MAKE=mingw32-make
LITEIDE_TERM=%COMSPEC%
LITEIDE_TERMARGS=
LITEIDE_EXEC=%COMSPEC%
LITEIDE_EXECOPT=/C

2 个答案:

答案 0 :(得分:3)

我知道这是一个老帖子,但是把它放在那里可以让其他人受益。

正是你在这里寻找的东西:

https://github.com/shirou/gopsutil

答案 1 :(得分:2)

这是一个简单的 Windows 示例,用于提取主机名,平台,CPU模型,总RAM和磁盘容量。首先安装模块:

@ViewBuilder
func moduleView(name: String) -> some View {
    switch name {
    case "module 1":
        View1()
    case "module 2":
        View2()
    default:
        View3()
    }
}

我在安装时遇到了问题,我还必须安装:

go get github.com/shirou/gopsutil 

现在运行以下代码:

go get github.com/StackExchange/wmi
相关问题