fix race condition in config updating

This commit is contained in:
ginuerzh
2023-01-20 10:27:21 +08:00
parent 40360f0c6f
commit 93b40f4c86
13 changed files with 272 additions and 229 deletions

View File

@ -35,13 +35,20 @@ func Global() *Config {
return cfg
}
func SetGlobal(c *Config) {
func Set(c *Config) {
globalMux.Lock()
defer globalMux.Unlock()
global = c
}
func OnUpdate(f func(c *Config) error) error {
globalMux.Lock()
defer globalMux.Unlock()
return f(global)
}
type LogConfig struct {
Output string `yaml:",omitempty" json:"output,omitempty"`
Level string `yaml:",omitempty" json:"level,omitempty"`