| 120 | } |
| 121 | |
| 122 | func (f *Func) call(ctx *Context, args ...interface{}) ([]reflect.Value, error) { |
| 123 | f.once.Do(f.buildMeta) |
| 124 | meta := f.Meta |
| 125 | |
| 126 | if meta.Handler != nil { |
| 127 | meta.Handler(ctx) |
| 128 | return nil, nil |
| 129 | } |
| 130 | |
| 131 | if meta.HandlerWithErr != nil { |
| 132 | return nil, meta.HandlerWithErr(ctx) |
| 133 | } |
| 134 | |
| 135 | if meta.RawFunc != nil { |
| 136 | meta.RawFunc() |
| 137 | return nil, nil |
| 138 | } |
| 139 | |
| 140 | if meta.RawFuncWithErr != nil { |
| 141 | return nil, meta.RawFuncWithErr() |
| 142 | } |
| 143 | |
| 144 | if meta.RawFuncArgs != nil { |
| 145 | meta.RawFuncArgs(args...) |
| 146 | return nil, nil |
| 147 | } |
| 148 | |
| 149 | if meta.RawFuncArgsWithErr != nil { |
| 150 | return nil, meta.RawFuncArgsWithErr(args...) |
| 151 | } |
| 152 | |
| 153 | inputs := make([]reflect.Value, 0, f.Meta.ExpectedArgumentsLength) |
| 154 | inputs = append(inputs, f.Meta.PersistenceInputs...) |
| 155 | if f.Meta.AcceptsContext { |
| 156 | inputs = append(inputs, reflect.ValueOf(ctx)) |
| 157 | } |
| 158 | |
| 159 | for _, arg := range args { |
| 160 | if in, ok := arg.(reflect.Value); ok { |
| 161 | inputs = append(inputs, in) |
| 162 | } else { |
| 163 | inputs = append(inputs, reflect.ValueOf(arg)) |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // keep it here, the inptus may contain the context. |
| 168 | if f.Meta.ExpectedArgumentsLength != len(inputs) { |
| 169 | return nil, ErrInvalidArgs |
| 170 | } |
| 171 | |
| 172 | outputs := f.Meta.Value.Call(inputs) |
| 173 | return outputs, getError(outputs) |
| 174 | } |
| 175 | |
| 176 | var contextType = reflect.TypeOf((*Context)(nil)) |
| 177 | |