add the concept of Id to a module

This commit is contained in:
Joel Wetzell
2025-11-18 19:13:14 -06:00
parent b3735ee713
commit 9ad60c8193
5 changed files with 61 additions and 18 deletions

View File

@@ -34,12 +34,23 @@ func NewRouter(ctx context.Context, config Config) (*Router, error) {
return nil, fmt.Errorf("problem loading module registration for module type: %s", moduleDecl.Type)
}
moduleInstance, err := moduleInfo.New(moduleDecl.Params)
if err != nil {
return nil, err
moduleInstanceExists := false
for _, moduleInstance := range router.ModuleInstances {
if moduleInstance.Id() == moduleDecl.Id {
moduleInstanceExists = true
slog.Warn("module id conflict", "id", moduleDecl.Id, "type", moduleDecl.Type)
break
}
}
router.ModuleInstances = append(router.ModuleInstances, moduleInstance)
if !moduleInstanceExists {
moduleInstance, err := moduleInfo.New(moduleDecl)
if err != nil {
return nil, err
}
router.ModuleInstances = append(router.ModuleInstances, moduleInstance)
}
}