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.
()
| 92 | // an error occurred, Reload will return early and abort the rest of the |
| 93 | // reloading. |
| 94 | func (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, |