forked from storezhang/echox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
option_serializer.go
53 lines (44 loc) · 997 Bytes
/
option_serializer.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
package echox
var (
_ httpOption = (*optionSerializer)(nil)
_ groupOption = (*optionSerializer)(nil)
)
type optionSerializer struct {
serializer serializer
}
// Proto 谷歌Protocol Buffer序列化
func Proto() *optionSerializer {
return &optionSerializer{
serializer: serializerProto,
}
}
// JSON 使用JSON序列化
func JSON() *optionSerializer {
return &optionSerializer{
serializer: serializerJson,
}
}
// XML 使用XML序列化
func XML() *optionSerializer {
return &optionSerializer{
serializer: serializerXml,
}
}
// Msgpack 使用Msgpack序列化
func Msgpack() *optionSerializer {
return &optionSerializer{
serializer: serializerMsgpack,
}
}
// Bytes 原始数据
func Bytes() *optionSerializer {
return &optionSerializer{
serializer: serializerBytes,
}
}
func (s *optionSerializer) applyHttp(options *httpOptions) {
options.serializer = s.serializer
}
func (s *optionSerializer) applyGroup(options *groupOptions) {
options.serializer = s.serializer
}