MCPcopy Create free account
hub / github.com/codnect/procyon / Register

Function Register

component/component.go:79–100  ·  view source on GitHub ↗

Register registers a new component using the given constructor function and optional definition options. It panics if the component name already exists or if definition creation fails.

(fn ConstructorFunc, opts ...DefinitionOption)

Source from the content-addressed store, hash-verified

77// Register registers a new component using the given constructor function and optional definition options.
78// It panics if the component name already exists or if definition creation fails.
79func Register(fn ConstructorFunc, opts ...DefinitionOption) *Registration {
80 muComponents.Lock()
81 defer muComponents.Unlock()
82
83 def, err := MakeDefinition(fn, opts...)
84 if err != nil {
85 panic(err)
86 }
87
88 name := def.Name()
89
90 if _, exists := components[name]; exists {
91 panic(fmt.Errorf("component with name '%s' already exists", name))
92 }
93
94 component := createComponent(def)
95
96 components[name] = component
97 return &Registration{
98 component: component,
99 }
100}
101
102// Load retrieves and constructs a component by its name, ensuring it matches the expected type T.
103// It returns an error if the component is not found, if there is a type mismatch, or if construction fails.

Callers 7

TestRegisterFunction · 0.85
TestListFunction · 0.85

Calls 3

MakeDefinitionFunction · 0.85
createComponentFunction · 0.85
NameMethod · 0.65

Tested by 7

TestRegisterFunction · 0.68
TestListFunction · 0.68