shirou/gopsutil#90 make hostinfo more robust

pull/91/head
Nick Galbreath 10 years ago
parent 6a274c3628
commit 99d93f93b2

@ -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()

Loading…
Cancel
Save