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

Method loadModuleMap

context.go:335–352  ·  context.go::Context.loadModuleMap

loadModuleMap loads modules from a ModuleMap, i.e. map[string]any, where the key is the module name. With a module map, module names do not need to be defined inline with their values.

(namespace string, val reflect.Value)

Source from the content-addressed store, hash-verified

333// loadModuleMap loads modules from a ModuleMap, i.e. map[string]any, where the key is the
334// module name. With a module map, module names do not need to be defined inline with their values.
335func (ctx Context) loadModuleMap(namespace string, val reflect.Value) (map[string]any, error) {
336 all := make(map[string]any)
337 iter := val.MapRange()
338 for iter.Next() {
339 k := iter.Key().Interface().(string)
340 v := iter.Value().Interface().(json.RawMessage)
341 moduleName := namespace + "." + k
342 if namespace == "" {
343 moduleName = k
344 }
345 val, err := ctx.LoadModuleByID(moduleName, v)
346 if err != nil {
347 return nil, fmt.Errorf("module name '%s': %v", k, err)
348 }
349 all[k] = val
350 }
351 return all, nil
352}
353
354// LoadModuleByID decodes rawMsg into a new instance of mod and
355// returns the value. If mod.New is nil, an error is returned.

Callers 1

Calls 3

LoadModuleByIDMethod · 0.95
NextMethod · 0.65
ValueMethod · 0.45

Tested by

no test coverage detected