@@ -7,41 +7,35 @@ import (
7
7
"reflect"
8
8
)
9
9
10
- var simpleRpcApi map [string ]reflect.Value = make (map [string ]reflect.Value )
11
-
12
- func Register (name string , T interface {}) {
13
- if _ , ok := simpleRpcApi [name ]; ok {
14
- return
15
- }
16
- simpleRpcApi [name ] = reflect .ValueOf (T )
17
- }
18
-
19
10
type Entry struct {
20
- MethodName string `json:"method_name"`
21
- Parameters map [string ]interface {} `json:"parameters"`
22
- MethodClass string `json:"method_class "`
23
- Options map [string ]interface {} `json:"options"`
11
+ MethodName string `json:"method_name"`
12
+ Parameters map [string ]interface {} `json:"parameters"`
13
+ ClassName string `json:"class_class "`
14
+ Options map [string ]interface {} `json:"options"`
24
15
}
25
16
26
17
type Result struct {
27
- Result interface {} `json:"result"`
18
+ Result [] interface {} `json:"result"`
28
19
}
29
20
30
- func (m * Entry ) Call () (interface {}, error ) {
31
- st := simpleRpcApi [m .MethodClass ]
21
+ func (m * Entry ) Call (s * Server ) ([] interface {}, error ) {
22
+ st := s . ApiSet [m .ClassName ]
32
23
args := make ([]reflect.Value , 0 , len (m .Parameters ))
33
24
for _ , arg := range m .Parameters {
34
25
args = append (args , reflect .ValueOf (arg ))
35
26
}
36
27
method := st .MethodByName (m .MethodName )
37
28
fmt .Println ("call class --> " , method , args )
38
29
39
- res := method .Call (args )
40
-
41
- return res , nil
30
+ out := method .Call (args )
31
+ outArgs := make ([]interface {}, 0 , len (out ))
32
+ for _ , o := range out {
33
+ outArgs = append (outArgs , o .Interface ())
34
+ }
35
+ return outArgs , nil
42
36
}
43
37
44
- func Handle (header map [string ]string , body []byte ) (interface {}, error ) {
38
+ func Handle (header map [string ]string , body []byte , s * Server ) ([] interface {}, error ) {
45
39
var entry Entry
46
40
// err := json.Unmarshal(body, &entry)
47
41
buf := bytes .NewBuffer (body )
@@ -53,5 +47,5 @@ func Handle(header map[string]string, body []byte) (interface{}, error) {
53
47
fmt .Println ("convert str to json error" , err )
54
48
return nil , err
55
49
}
56
- return entry .Call ()
50
+ return entry .Call (s )
57
51
}
0 commit comments