MCPcopy Create free account
hub / github.com/golobby/container / invoke

Method invoke

container.go:97–110  ·  view source on GitHub ↗

invoke calls a function and its returned values. It only accepts one value and an optional error.

(function interface{})

Source from the content-addressed store, hash-verified

95// invoke calls a function and its returned values.
96// It only accepts one value and an optional error.
97func (c Container) invoke(function interface{}) (interface{}, error) {
98 arguments, err := c.arguments(function)
99 if err != nil {
100 return nil, err
101 }
102
103 values := reflect.ValueOf(function).Call(arguments)
104 if len(values) == 2 && values[1].CanInterface() {
105 if err, ok := values[1].Interface().(error); ok {
106 return values[0].Interface(), err
107 }
108 }
109 return values[0].Interface(), nil
110}
111
112// arguments returns the list of resolved arguments for a function.
113func (c Container) arguments(function interface{}) ([]reflect.Value, error) {

Callers 2

bindMethod · 0.95
makeMethod · 0.80

Calls 2

argumentsMethod · 0.95
CallMethod · 0.80

Tested by

no test coverage detected