implements Host.Uptime on windows

This commit is contained in:
WAKAYAMA Shirou 2014-04-18 22:02:35 +09:00
parent ce81975573
commit 5fc807ed23
1 changed files with 11 additions and 0 deletions

View File

@ -4,6 +4,7 @@ package main
import ( import (
"os" "os"
"syscall"
) )
func (h Host) HostInfo() (HostInfo, error) { func (h Host) HostInfo() (HostInfo, error) {
@ -15,5 +16,15 @@ func (h Host) HostInfo() (HostInfo, error) {
ret.Hostname = hostname ret.Hostname = hostname
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return ret, err
}
defer syscall.FreeLibrary(kernel32)
GetTickCount, _ := syscall.GetProcAddress(kernel32, "GetTickCount")
uptimemsec, _, err := syscall.Syscall(uintptr(GetTickCount), 0, 0, 0, 0)
ret.Uptime = int64(uptimemsec) / 1000
return ret, nil return ret, nil
} }