mirror of
https://github.com/yusing/godoxy.git
synced 2026-01-11 21:10:30 +01: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")
|
||||
|
||||
@@ -774,7 +774,7 @@ func (r *Route) Finalize() {
|
||||
}
|
||||
|
||||
r.Port.Listening, r.Port.Proxy = lp, pp
|
||||
r.HealthCheck.ApplyDefaults(config.ActiveConfig.Load().Defaults.HealthCheck)
|
||||
r.HealthCheck.ApplyDefaults(config.WorkingState.Load().Value().Defaults.HealthCheck)
|
||||
}
|
||||
|
||||
func (r *Route) FinalizeHomepageConfig() {
|
||||
|
||||
@@ -36,6 +36,9 @@ func (hc *HealthCheckConfig) ApplyDefaults(defaults HealthCheckConfig) {
|
||||
}
|
||||
}
|
||||
if hc.Retries == 0 {
|
||||
hc.Retries = int64(HealthCheckDownNotifyDelayDefault / hc.Interval)
|
||||
hc.Retries = defaults.Retries
|
||||
if hc.Retries == 0 {
|
||||
hc.Retries = max(1, int64(HealthCheckDownNotifyDelayDefault/hc.Interval))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,15 @@ func NewMonitor(r types.Route) types.HealthMonCheck {
|
||||
}
|
||||
|
||||
func newMonitor(u *url.URL, cfg types.HealthCheckConfig, healthCheckFunc HealthCheckFunc) *monitor {
|
||||
cfg.ApplyDefaults(config.DefaultConfig().Defaults.HealthCheck)
|
||||
state := config.WorkingState.Load()
|
||||
if state == nil {
|
||||
state = config.ActiveState.Load()
|
||||
}
|
||||
if state != nil {
|
||||
cfg.ApplyDefaults(state.Value().Defaults.HealthCheck)
|
||||
} else {
|
||||
cfg.ApplyDefaults(types.HealthCheckConfig{}) // use config defaults
|
||||
}
|
||||
mon := &monitor{
|
||||
config: cfg,
|
||||
checkHealth: healthCheckFunc,
|
||||
|
||||
Reference in New Issue
Block a user