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

Method loadModulesFromSomeMap

context.go:300–313  ·  view source on GitHub ↗

loadModulesFromSomeMap loads modules from val, which must be a type of map[string]any. Depending on inlineModuleKey, it will be interpreted as either a ModuleMap (key is the module name) or as a regular map (key is not the module name, and module name is defined inline).

(namespace, inlineModuleKey string, val reflect.Value)

Source from the content-addressed store, hash-verified

298// Depending on inlineModuleKey, it will be interpreted as either a ModuleMap (key is the module
299// name) or as a regular map (key is not the module name, and module name is defined inline).
300func (ctx Context) loadModulesFromSomeMap(namespace, inlineModuleKey string, val reflect.Value) (map[string]any, error) {
301 // if no inline_key is specified, then val must be a ModuleMap,
302 // where the key is the module name
303 if inlineModuleKey == "" {
304 if !isModuleMapType(val.Type()) {
305 panic(fmt.Sprintf("expected ModuleMap because inline_key is empty; but we do not recognize this type: %s", val.Type()))
306 }
307 return ctx.loadModuleMap(namespace, val)
308 }
309
310 // otherwise, val is a map with modules, but the module name is
311 // inline with each value (the key means something else)
312 return ctx.loadModulesFromRegularMap(namespace, inlineModuleKey, val)
313}
314
315// loadModulesFromRegularMap loads modules from val, where val is a map[string]json.RawMessage.
316// Map keys are NOT interpreted as module names, so module names are still expected to appear

Callers 1

LoadModuleMethod · 0.95

Calls 4

loadModuleMapMethod · 0.95
isModuleMapTypeFunction · 0.85
TypeMethod · 0.45

Tested by

no test coverage detected