forked from lonng/nano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
93 lines (80 loc) · 2.21 KB
/
options.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
package connector
import (
"github.com/aura-studio/nano/codec"
"github.com/aura-studio/nano/log"
"github.com/aura-studio/nano/message"
"github.com/aura-studio/nano/serializer"
)
type (
// Options contains some configurations for connector
Options struct {
name string // component name
Serializer serializer.Serializer // serializer for connector
WebSocketPath string // websocket path
IsWebSocket bool // is websocket
Logger log.Logger // logger
Codec codec.Codec // codec
Dictionary message.Dictionary // dictionary
Branch uint32
ShortVersion uint32
WebSocketCompression bool
}
// Option used to customize handler
Option func(options *Options)
)
// WithName is used to name connector
func WithName(name string) Option {
return func(opt *Options) {
opt.name = name
}
}
// WithSerializerType customizes application serializer, which automatically Marshal
// and UnMarshal handler payload
func WithSerializer(serializer serializer.Serializer) Option {
return func(opt *Options) {
opt.Serializer = serializer
}
}
// WithWebSocketPath set the websocket path
func WithWebSocketPath(path string) Option {
return func(opt *Options) {
opt.WebSocketPath = path
}
}
func WithIsWebSocket(isWebSocket bool) Option {
return func(opt *Options) {
opt.IsWebSocket = isWebSocket
}
}
// WithLogger overrides the default logger
func WithLogger(l log.Logger) Option {
return func(opt *Options) {
opt.Logger = l
}
}
// WithCodec sets codec instead of default codec
func WithCodec(codec codec.Codec) Option {
return func(opt *Options) {
opt.Codec = codec
}
}
func WithDictionary(dictionary message.Dictionary) Option {
return func(opt *Options) {
opt.Dictionary = dictionary
}
}
func WithBranch(branch uint32) Option {
return func(opt *Options) {
opt.Branch = branch
}
}
func WithShortVersion(shortVersion uint32) Option {
return func(opt *Options) {
opt.ShortVersion = shortVersion
}
}
func WithWebSocketCompression(webSocketCompression bool) Option {
return func(opt *Options) {
opt.WebSocketCompression = webSocketCompression
}
}