goProject/.svn/pristine/0a/0a32a7aadf4e5244aa44094b27c6e4e39d8a1f2d.svn-base
2025-01-06 16:21:36 +08:00

40 lines
965 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package reloadMgr
import (
"fmt"
"goutil/logUtil"
)
var (
reloadFuncMap = make(map[string]func() error)
)
// RegisterReloadFunc ...注册Reload方法
// funcName:方法名称
// reloadFuncreload方法
func RegisterReloadFunc(funcName string, reloadFunc func() error) {
if _, exists := reloadFuncMap[funcName]; exists {
panic(fmt.Sprintf("%s已经存在请重新取名", funcName))
}
reloadFuncMap[funcName] = reloadFunc
logUtil.InfoLog(fmt.Sprintf("RegisterReloadFunc funcName:%s当前共有%d个注册", funcName, len(reloadFuncMap)))
}
// Reload ...重新加载
// 返回值:
// 错误列表
func Reload() (errList []error) {
for funcName, reloadFunc := range reloadFuncMap {
if err := reloadFunc(); err == nil {
logUtil.InfoLog(fmt.Sprintf("Call ReloadFunc:%s Success.", funcName))
} else {
logUtil.ErrorLog(fmt.Sprintf("Call ReloadFunc:%s Fail, Error:%s", funcName, err))
errList = append(errList, err)
}
}
return
}