-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_parse.go
More file actions
49 lines (36 loc) · 732 Bytes
/
Copy pathfunc_parse.go
File metadata and controls
49 lines (36 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package muxplus
import (
"reflect"
)
type Func struct {
Name string
In []reflect.Type
Out []reflect.Type
Func reflect.Value
}
func FuncParse(function interface{}) (ret *Func) {
var (
funcType reflect.Type
numIn int
numOut int
)
ret = new(Func)
if function == nil {
panic("function can't be nil")
}
funcType = reflect.TypeOf(function)
if funcType.Kind() != reflect.Func {
panic("function must be func")
}
ret.Name = funcType.Name()
numIn = funcType.NumIn()
numOut = funcType.NumOut()
for i := 0; i < numIn; i++ {
ret.In = append(ret.In, funcType.In(i))
}
for i := 0; i < numOut; i++ {
ret.Out = append(ret.Out, funcType.Out(i))
}
ret.Func = reflect.ValueOf(function)
return
}