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)
| 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. |
| 335 | func (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. |
no test coverage detected