Load loads the given config JSON and runs it only if it is different from the current config or forceReload is true.
(cfgJSON []byte, forceReload bool)
| 113 | // if it is different from the current config or |
| 114 | // forceReload is true. |
| 115 | func Load(cfgJSON []byte, forceReload bool) error { |
| 116 | if err := notify.Reloading(); err != nil { |
| 117 | Log().Error("unable to notify service manager of reloading state", zap.Error(err)) |
| 118 | } |
| 119 | |
| 120 | // after reload, notify system of success or, if |
| 121 | // failure, update with status (error message) |
| 122 | var err error |
| 123 | defer func() { |
| 124 | if err != nil { |
| 125 | if notifyErr := notify.Error(err, 0); notifyErr != nil { |
| 126 | Log().Error("unable to notify to service manager of reload error", |
| 127 | zap.Error(notifyErr), |
| 128 | zap.String("reload_err", err.Error())) |
| 129 | } |
| 130 | } |
| 131 | if notifyErr := notify.Ready(); notifyErr != nil { |
| 132 | Log().Error("unable to notify to service manager of ready state", zap.Error(notifyErr)) |
| 133 | } |
| 134 | }() |
| 135 | |
| 136 | err = changeConfig(http.MethodPost, "/"+rawConfigKey, cfgJSON, "", forceReload) |
| 137 | if errors.Is(err, errSameConfig) { |
| 138 | err = nil // not really an error |
| 139 | } |
| 140 | |
| 141 | return err |
| 142 | } |
| 143 | |
| 144 | // changeConfig changes the current config (rawCfg) according to the |
| 145 | // method, traversed via the given path, and uses the given input as |