MCPcopy
hub / github.com/caddyserver/caddy / Load

Function Load

caddy.go:115–142  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

113// if it is different from the current config or
114// forceReload is true.
115func 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

Callers 4

TestLoadConcurrentFunction · 0.85
TestETagsFunction · 0.85
BenchmarkLoadFunction · 0.85
RunFunction · 0.85

Calls 7

ReloadingFunction · 0.92
ErrorFunction · 0.92
ReadyFunction · 0.92
LogFunction · 0.85
changeConfigFunction · 0.85
ErrorMethod · 0.45
StringMethod · 0.45

Tested by 3

TestLoadConcurrentFunction · 0.68
TestETagsFunction · 0.68
BenchmarkLoadFunction · 0.68