-
Notifications
You must be signed in to change notification settings - Fork 5
/
doc.go
83 lines (60 loc) · 2.12 KB
/
doc.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package docs
import (
"context"
"errors"
"github.com/topfreegames/pitaya"
"github.com/topfreegames/pitaya-admin/protos"
)
// GetDocumentationForServerType gets documentation for given server type.
func GetDocumentationForServerType(serverType, docsRemoteRoute string, flag bool) (map[string]interface{}, error) {
var ret map[string]interface{}
responseProto := &protos.Doc{}
route := serverType + "." + docsRemoteRoute
err := pitaya.RPC(context.Background(), route, responseProto, &protos.DocMsg{GetProtos: flag})
if err != nil {
return nil, err
}
err = pitaya.GetSerializer().Unmarshal([]byte(responseProto.GetDoc()), &ret)
if err != nil {
return nil, err
}
return ret, nil
}
func getRemotesDoc(serverType, docsRemoteRoute string, flag bool) (map[string]interface{}, error) {
ret, err := GetDocumentationForServerType(serverType, docsRemoteRoute, flag)
if err != nil {
return nil, err
}
rM := ret["remotes"]
retMap, _ := rM.(map[string]interface{})
return retMap, nil
}
func getHandlersDoc(serverType, docsRemoteRoute string, flag bool) (map[string]interface{}, error) {
ret, err := GetDocumentationForServerType(serverType, docsRemoteRoute, flag)
if err != nil {
return nil, err
}
rM := ret["handlers"]
retMap, ok := rM.(map[string]interface{})
if !ok {
return nil, errors.New("Fail")
}
return retMap, nil
}
// GetDocForHandlersOrRemotes gets only remote or handler docs for given servertype
func GetDocForHandlersOrRemotes(servertype, handlerOrRemote, docsRemoteRoute string, flag bool) (map[string]interface{}, error) {
if handlerOrRemote == "remote" {
return getRemotesDoc(servertype, docsRemoteRoute, flag)
}
return getHandlersDoc(servertype, docsRemoteRoute, flag)
}
// GetMethodDoc gets documentation for a method given its route and whether it's a remote or a handler
func GetMethodDoc(servertype, methodType, route, docsRemoteRoute string, flag bool) (map[string]interface{}, error) {
ret, err := GetDocForHandlersOrRemotes(servertype, methodType, docsRemoteRoute, flag)
if err != nil {
return nil, err
}
rM := ret[route]
retMap, _ := rM.(map[string]interface{})
return retMap, nil
}