(key string, i interface{})
| 182 | } |
| 183 | |
| 184 | func registerFunction(key string, i interface{}) (*Function, error) { |
| 185 | f := &Function{fv: reflect.ValueOf(i)} |
| 186 | f.key = key |
| 187 | |
| 188 | t := f.fv.Type() |
| 189 | if t.Kind() != reflect.Func { |
| 190 | f.err = errors.New("not a function") |
| 191 | return f, f.err |
| 192 | } |
| 193 | if t.NumIn() == 0 || !isContext(t.In(0)) { |
| 194 | f.err = errFirstArg |
| 195 | return f, errFirstArg |
| 196 | } |
| 197 | |
| 198 | // Register the function's arguments with the gob package. |
| 199 | // This is required because they are marshaled inside a []interface{}. |
| 200 | // gob.Register only expects to be called during initialization; |
| 201 | // that's fine because this function expects the same. |
| 202 | for i := 0; i < t.NumIn(); i++ { |
| 203 | // Only concrete types may be registered. If the argument has |
| 204 | // interface type, the client is resposible for registering the |
| 205 | // concrete types it will hold. |
| 206 | if t.In(i).Kind() == reflect.Interface { |
| 207 | continue |
| 208 | } |
| 209 | gob.Register(reflect.Zero(t.In(i)).Interface()) |
| 210 | } |
| 211 | return f, nil |
| 212 | } |
| 213 | |
| 214 | type invocation struct { |
| 215 | Key string |
no test coverage detected
searching dependent graphs…