支持注册配置刷新事件
This commit is contained in:
parent
ce71a956e5
commit
fe90f34770
|
@ -11,6 +11,21 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type RefreshEvent func()
|
||||
|
||||
var configRefreshEventHandles []func()
|
||||
|
||||
// RegConfigRefreshEvent 当配置刷新时将立即执行被注册的事件处理函数
|
||||
func RegConfigRefreshEvent(handle RefreshEvent) {
|
||||
configRefreshEventHandles = append(configRefreshEventHandles, handle)
|
||||
}
|
||||
|
||||
func OnConfigRefreshEvent() {
|
||||
for _, handle := range configRefreshEventHandles {
|
||||
handle()
|
||||
}
|
||||
}
|
||||
|
||||
type LoadHandle func(handle func(filename string, config any) error)
|
||||
type RefreshHandle func()
|
||||
|
||||
|
@ -74,5 +89,6 @@ func StopTickerLoad() {
|
|||
func Refresh() {
|
||||
mutex.Lock()
|
||||
cRefreshHandle()
|
||||
OnConfigRefreshEvent()
|
||||
mutex.Unlock()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue