-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
68 lines (51 loc) · 1.46 KB
/
handler.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
package drpc
import "reflect"
type Handler struct {
// 绑定的handler名
name string
//参数类型
argElem reflect.Type
//返回值类型 注意:只有call消息才会有
reply reflect.Type
//处理该消息的方法
handleFunc func(*handlerCtx, reflect.Value)
// 不能匹配到绑定方法时,默认的处理方法
unknownHandleFunc func(*handlerCtx)
pluginContainer *PluginContainer
// 路由类型名字
routerTypeName string
//是否找到绑定方法
isUnknown bool
}
// RouterTypeName 获取处理器的路由方法名 pnPush/pnCall/pnUnknownPush/pnUnknownCall
func (that *Handler) RouterTypeName() string {
return that.routerTypeName
}
// ReplyType 回复消息的类型
func (that *Handler) ReplyType() reflect.Type {
return that.reply
}
// Name 名字
func (that *Handler) Name() string {
return that.name
}
// NewArgValue 参数的反射值
func (that *Handler) NewArgValue() reflect.Value {
return reflect.New(that.argElem)
}
// ArgElemType 参数的类型
func (that *Handler) ArgElemType() reflect.Type {
return that.argElem
}
// IsCall 处理程序是否是Call
func (that *Handler) IsCall() bool {
return that.routerTypeName == pnCall || that.routerTypeName == pnUnknownCall
}
// IsPush 处理程序是否是PUSH
func (that *Handler) IsPush() bool {
return that.routerTypeName == pnPush || that.routerTypeName == pnUnknownPush
}
// IsUnknown 处理程序是否未找到
func (that *Handler) IsUnknown() bool {
return that.isUnknown
}