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

Function WithQualifierFor

component/definition.go:177–196  ·  view source on GitHub ↗

WithQualifierFor sets a named qualifier for the constructor argument that matches the given type T.

(name string)

Source from the content-addressed store, hash-verified

175// WithQualifierFor sets a named qualifier for the constructor argument
176// that matches the given type T.
177func WithQualifierFor[T any](name string) DefinitionOption {
178 return func(def *Definition) error {
179 typ := reflect.TypeFor[T]()
180 objectConstructor := def.constructor
181
182 exists := false
183 for index, arg := range objectConstructor.Args() {
184 if arg.Type() == typ {
185 objectConstructor.args[index].name = name
186 exists = true
187 }
188 }
189
190 if !exists {
191 return fmt.Errorf("no constructor input of type %s", typ.Name())
192 }
193
194 return nil
195 }
196}

Callers

nothing calls this directly

Calls 3

ArgsMethod · 0.80
NameMethod · 0.65
TypeMethod · 0.45

Tested by

no test coverage detected