MCPcopy Create free account
hub / github.com/DoNewsCode/core / Reload

Method Reload

config/config.go:94–119  ·  view source on GitHub ↗

Reload reloads the whole configuration stack. It reloads layer by layer, so if an error occurred, Reload will return early and abort the rest of the reloading.

()

Source from the content-addressed store, hash-verified

92// an error occurred, Reload will return early and abort the rest of the
93// reloading.
94func (k *KoanfAdapter) Reload() error {
95 tmp := koanf.New(".")
96
97 for i := len(k.layers) - 1; i >= 0; i-- {
98 err := tmp.Load(k.layers[i].Provider, k.layers[i].Parser)
99 if err != nil {
100 return fmt.Errorf("unable to load config %w", err)
101 }
102 }
103
104 for _, f := range k.validators {
105 if err := f(tmp.Raw()); err != nil {
106 return fmt.Errorf("validation failed: %w", err)
107 }
108 }
109
110 k.rwlock.Lock()
111 k.K = tmp
112 k.rwlock.Unlock()
113
114 if k.dispatcher != nil {
115 k.dispatcher.Dispatch(context.Background(), events.OnReload, events.OnReloadPayload{NewConf: k})
116 }
117
118 return nil
119}
120
121// Watch uses the internal watcher to watch the configuration reload signals.
122// This function should be registered in the run group. If the watcher is nil,

Callers 3

NewConfigFunction · 0.95
TestKoanfAdapter_raceFunction · 0.80
TestKoanfAdapter_WatchFunction · 0.80

Calls 1

DispatchMethod · 0.65

Tested by 2

TestKoanfAdapter_raceFunction · 0.64
TestKoanfAdapter_WatchFunction · 0.64