1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-05-04 22:17:34 +08:00

Merge pull request #91 from client9/master

shirou/gopsutil#90 make hostinfo more robust
This commit is contained in:
shirou 2015-10-14 15:56:17 +09:00
commit 7f6e8da3d0
4 changed files with 30 additions and 38 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -26,14 +26,13 @@ type LSB struct {
}
func HostInfo() (*HostInfoStat, error) {
hostname, err := os.Hostname()
if err != nil {
return nil, err
ret := &HostInfoStat{
OS: runtime.GOOS,
}
ret := &HostInfoStat{
Hostname: hostname,
OS: runtime.GOOS,
hostname, err := os.Hostname()
if err == nil {
ret.Hostname = hostname
}
platform, family, version, err := GetPlatformInformation()

View File

@ -3,11 +3,11 @@
package host
import (
"os"
"fmt"
"time"
"os"
"runtime"
"strings"
"time"
"github.com/StackExchange/wmi"
@ -29,14 +29,13 @@ type Win32_OperatingSystem struct {
}
func HostInfo() (*HostInfoStat, error) {
hostname, err := os.Hostname()
if err != nil {
return nil, err
ret := &HostInfoStat{
OS: runtime.GOOS,
}
ret := &HostInfoStat{
Hostname: hostname,
OS: runtime.GOOS,
hostname, err := os.Hostname()
if err == nil {
ret.Hostname = hostname
}
platform, family, version, err := GetPlatformInformation()
@ -44,8 +43,6 @@ func HostInfo() (*HostInfoStat, error) {
ret.Platform = platform
ret.PlatformFamily = family
ret.PlatformVersion = version
} else {
return ret, err
}
ret.Uptime, err = BootTime()