mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 23:20:25 +08:00
可以在集群中指定节点时区
This commit is contained in:
34
internal/nodes/timezone.go
Normal file
34
internal/nodes/timezone.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package nodes
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/events"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// 管理时区
|
||||
var lastTimeZone = ""
|
||||
|
||||
events.On(events.EventReload, func() {
|
||||
if sharedNodeConfig != nil {
|
||||
var timeZone = sharedNodeConfig.TimeZone
|
||||
if len(timeZone) == 0 {
|
||||
timeZone = "Asia/Shanghai"
|
||||
}
|
||||
|
||||
location, err := time.LoadLocation(sharedNodeConfig.TimeZone)
|
||||
if err != nil {
|
||||
remotelogs.Error("TIMEZONE", "change time zone failed: "+err.Error())
|
||||
return
|
||||
}
|
||||
if lastTimeZone != timeZone {
|
||||
remotelogs.Println("TIMEZONE", "change time zone to '"+timeZone+"'")
|
||||
time.Local = location
|
||||
lastTimeZone = timeZone
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user