-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.go
95 lines (79 loc) · 1.73 KB
/
type.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
84
85
86
87
88
89
90
91
92
93
94
95
package rpc
import (
"fmt"
"github.com/erdong01/kit/base"
"reflect"
"strings"
)
type (
ICluster interface {
SendMsg(head RpcHead, funcName string, params ...interface{})
Call(parmas ...interface{})
Id() uint32
}
)
var MGR ICluster
func Route(head *RpcHead, funcName string) string {
serverArgs := strings.Split(funcName, "<-")
if len(serverArgs) == 2 {
switch strings.ToLower(serverArgs[0]) {
case "client":
head.DestServerType = SERVICE_CLIENT
case "gate":
head.DestServerType = SERVICE_GATE
case "gm":
head.DestServerType = SERVICE_GM
case "game":
head.DestServerType = SERVICE_GAME
case "zone":
head.DestServerType = SERVICE_ZONE
case "db":
head.DestServerType = SERVICE_DB
}
funcName = serverArgs[1]
}
actorArgs := strings.Split(funcName, ".")
if len(actorArgs) == 2 {
head.ActorName = actorArgs[0]
funcName = actorArgs[1]
}
return funcName
}
type (
//集群信息
IClusterInfo interface {
Id() uint32
ServiceName() string
ServiceType() SERVICE
IpString() string
}
)
func (c *ClusterInfo) IpString() string {
return fmt.Sprintf("%s:%d", c.Ip, c.Port)
}
func (c *ClusterInfo) ServiceName() string {
return strings.ToLower(c.Type.String())
}
func (c *ClusterInfo) Id() uint32 {
return base.ToHash(c.IpString())
}
func (c *ClusterInfo) ServiceType() SERVICE {
return c.Type
}
func (s *StubMailBox) StubName() string {
return s.StubType.String()
}
func (s *StubMailBox) Key() string {
return fmt.Sprintf("%s/%d", s.StubType.String(), s.Id)
}
// params[0]:rpc.RpcHead
// params[1]:error
func Call(parmas ...interface{}) {
/*head := *parmas[0].(*RpcHead)
if parmas[1] == nil{
parmas[1] = ""
}else{
parmas[1] = parmas[1].(error).Error()
}*/
}
var GCall = reflect.ValueOf(Call)