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

Function createConstructor

component/constructor.go:36–55  ·  view source on GitHub ↗

createConstructor validates the given ConstructorFunc and builds a Constructor metadata struct. It ensures that the function is non-nil, is of kind Func, and returns exactly one result. If valid, it extracts the argument types and returns a populated Constructor.

(fn ConstructorFunc)

Source from the content-addressed store, hash-verified

34// It ensures that the function is non-nil, is of kind Func, and returns exactly one result.
35// If valid, it extracts the argument types and returns a populated Constructor.
36func createConstructor(fn ConstructorFunc) (Constructor, error) {
37 if fn == nil {
38 return Constructor{}, fmt.Errorf("nil constructor")
39 }
40
41 fnType := reflect.TypeOf(fn)
42 if fnType.Kind() != reflect.Func {
43 return Constructor{}, fmt.Errorf("constructor must be a function")
44 }
45
46 if fnType.NumOut() != 1 {
47 return Constructor{}, fmt.Errorf("constructor must only return one result")
48 }
49
50 return Constructor{
51 fnType: fnType,
52 fnValue: reflect.ValueOf(fn),
53 args: extractConstructorArgs(fnType),
54 }, nil
55}
56
57// OutType returns the type of the constructor function's output.
58func (f Constructor) OutType() reflect.Type {

Callers 4

MakeDefinitionFunction · 0.85
TestCreateConstructorFunction · 0.85
TestConstructor_InvokeFunction · 0.85

Calls 1

extractConstructorArgsFunction · 0.85

Tested by 3

TestCreateConstructorFunction · 0.68
TestConstructor_InvokeFunction · 0.68