mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-20 15:31:24 +02:00
fix(config): fix default values not applied
This commit is contained in:
@@ -52,11 +52,16 @@ func logNotifyWarn(action string, err error) {
|
||||
})
|
||||
}
|
||||
|
||||
var nilState *state
|
||||
|
||||
func Load() error {
|
||||
if HasState() {
|
||||
panic(errors.New("config already loaded"))
|
||||
}
|
||||
state := NewState()
|
||||
config.WorkingState.Store(state)
|
||||
defer config.WorkingState.Store(nilState)
|
||||
|
||||
cfgWatcher = watcher.NewConfigFileWatcher(common.ConfigFileName)
|
||||
|
||||
initErr := state.InitFromFile(common.ConfigPath)
|
||||
@@ -82,6 +87,9 @@ func Reload() gperr.Error {
|
||||
defer reloadMu.Unlock()
|
||||
|
||||
newState := NewState()
|
||||
config.WorkingState.Store(newState)
|
||||
defer config.WorkingState.Store(nilState)
|
||||
|
||||
err := newState.InitFromFile(common.ConfigPath)
|
||||
if err != nil {
|
||||
newState.Task().FinishAndWait(err)
|
||||
|
||||
@@ -33,7 +33,10 @@ type State interface {
|
||||
FlushTmpLog()
|
||||
}
|
||||
|
||||
// could be nil
|
||||
// could be nil before first call on Load
|
||||
var ActiveState synk.Value[State]
|
||||
|
||||
// nil-safe while loading config, nil otherwise
|
||||
var WorkingState synk.Value[State]
|
||||
|
||||
var ErrConfigChanged = errors.New("config changed")
|
||||
|
||||
Reference in New Issue
Block a user