我正在尝试检索我的Go
应用程序的当前正常运行时间。
我已经看到有一个包syscall
提供了一个type Sysinfo_t
和一个方法Sysinfo(*Sysinfo_t)
,它显然允许您检索正常运行时间(因为它是Sysinfo_t
结构的一个字段)
到目前为止我所做的是:
sysi := &syscall.Sysinfo_t{}
if err := syscall.Sysinfo(sysi); err != nil {
return http.StatusInternalServerError, nil
}
问题是在编译时我得到了这个:
/path/to/file/res_system.go:43: undefined: syscall.Sysinfo_t
/path/to/file/res_system.go:45: undefined: syscall.Sysinfo
我搜索了一下,显然该方法和类型仅在 Linux 上可用,我需要该应用程序在 Linux 和 OsX(我目前正在使用)上运行。
是否有一种交叉兼容的方式来检索应用程序的正常运行时间?
注意:我宁愿不使用任何第三方库(除非它们是绝对必要的)