mirror of
https://github.com/unpoller/unpoller.git
synced 2026-04-05 00:44:09 -04:00
Add TZ env usage to set local time zone.
This commit is contained in:
17
main.go
17
main.go
@@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/unifi-poller/poller"
|
||||
|
||||
@@ -16,7 +18,22 @@ import (
|
||||
|
||||
// Keep it simple.
|
||||
func main() {
|
||||
// Set time zone based on TZ env variable.
|
||||
setTimeZone(os.Getenv("TZ"))
|
||||
|
||||
if err := poller.New().Start(); err != nil {
|
||||
log.Fatalln("[ERROR]", err)
|
||||
}
|
||||
}
|
||||
|
||||
func setTimeZone(tz string) {
|
||||
if tz == "" {
|
||||
return
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
if time.Local, err = time.LoadLocation(tz); err != nil {
|
||||
log.Printf("[ERROR] Loading TZ Location '%s': %v\n", tz, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user