提交 99d93f93 编写于 作者: N Nick Galbreath

shirou/gopsutil#90 make hostinfo more robust

上级 6a274c36
......@@ -23,10 +23,9 @@ func HostInfo() (*HostInfoStat, error) {
}
hostname, err := os.Hostname()
if err != nil {
return ret, err
}
if err == nil {
ret.Hostname = hostname
}
platform, family, version, err := GetPlatformInformation()
if err == nil {
......@@ -46,10 +45,9 @@ func HostInfo() (*HostInfoStat, error) {
v := strings.Replace(values[2], ",", "", 1)
t, err := strconv.ParseUint(v, 10, 64)
if err != nil {
return ret, err
}
ret.Uptime = t
}
}
return ret, nil
}
......
......@@ -29,10 +29,9 @@ func HostInfo() (*HostInfoStat, error) {
}
hostname, err := os.Hostname()
if err != nil {
return ret, err
}
if err == nil {
ret.Hostname = hostname
}
platform, family, version, err := GetPlatformInformation()
if err == nil {
......@@ -51,11 +50,10 @@ func HostInfo() (*HostInfoStat, error) {
// ex: { sec = 1392261637, usec = 627534 } Thu Feb 13 12:20:37 2014
v := strings.Replace(values[2], ",", "", 1)
t, err := strconv.ParseUint(v, 10, 64)
if err != nil {
return ret, err
}
if err == nil {
ret.Uptime = t
}
}
return ret, nil
}
......
......@@ -26,16 +26,15 @@ type LSB struct {
}
func HostInfo() (*HostInfoStat, error) {
hostname, err := os.Hostname()
if err != nil {
return nil, err
}
ret := &HostInfoStat{
Hostname: hostname,
OS: runtime.GOOS,
}
hostname, err := os.Hostname()
if err == nil {
ret.Hostname = hostname
}
platform, family, version, err := GetPlatformInformation()
if err == nil {
ret.Platform = platform
......
......@@ -3,11 +3,11 @@
package host
import (
"os"
"fmt"
"time"
"os"
"runtime"
"strings"
"time"
"github.com/StackExchange/wmi"
......@@ -29,23 +29,20 @@ type Win32_OperatingSystem struct {
}
func HostInfo() (*HostInfoStat, error) {
hostname, err := os.Hostname()
if err != nil {
return nil, err
}
ret := &HostInfoStat{
Hostname: hostname,
OS: runtime.GOOS,
}
hostname, err := os.Hostname()
if err == nil {
ret.Hostname = hostname
}
platform, family, version, err := GetPlatformInformation()
if err == nil {
ret.Platform = platform
ret.PlatformFamily = family
ret.PlatformVersion = version
} else {
return ret, err
}
ret.Uptime, err = BootTime()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册