Skip to content

Commit 80ce406

Browse files
author
wintrmvte
committed
+ TimeNTP() for obtaining time.Now() from remote server
1 parent 9857610 commit 80ce406

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

os.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import (
88
"log"
99
"os"
1010
"strings"
11+
"time"
1112

1213
"github.com/matishsiao/goInfo"
1314
"github.com/mitchellh/go-homedir"
15+
"github.com/beevik/ntp"
1416
ps "github.com/mitchellh/go-ps"
1517
)
1618

@@ -53,6 +55,15 @@ func Info() map[string]string {
5355
return inf
5456
}
5557

58+
// Obtains current time from NTP server
59+
func TimeNTP() time.Time {
60+
ntp_time, err := ntp.Time("time.ntp.com")
61+
if (err != nil){
62+
ntp_time, _ = ntp.Time("time.apple.com")
63+
}
64+
return ntp_time
65+
}
66+
5667
// PkillPid kills a process by its PID.
5768
func PkillPid(pid int) error {
5869
err := KillProcByPID(pid)

0 commit comments

Comments
 (0)