-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
145 lines (124 loc) · 3.41 KB
/
option.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package ramix
import "time"
var defaultServerOptions = ServerOptions{
OnlyWebSocket: false,
OnlyTCP: false,
Name: "ramix",
IP: "0.0.0.0",
IPVersion: "tcp4",
Port: 8899,
WebSocketPort: 8900,
WebSocketPath: "/ws",
MaxConnectionsCount: 1024,
ConnectionGroupsCount: 10,
ConnectionReadBufferSize: 1024,
ConnectionWriteBufferSize: 1024,
MaxWorkerTasksCount: 1024,
HeartbeatInterval: 5 * time.Second,
HeartbeatTimeout: 60 * time.Second,
}
type ServerOptions struct {
OnlyWebSocket bool
OnlyTCP bool
Name string
IPVersion string
IP string
Port int
WebSocketPort int
WebSocketPath string
CertFile string
PrivateKeyFile string
MaxConnectionsCount int
ConnectionGroupsCount int
ConnectionReadBufferSize uint32
ConnectionWriteBufferSize uint32
MaxWorkerTasksCount uint32
HeartbeatInterval time.Duration
HeartbeatTimeout time.Duration
}
type ServerOption func(*ServerOptions)
func OnlyWebSocket() ServerOption {
return func(o *ServerOptions) {
o.OnlyWebSocket = true
}
}
func OnlyTCP() ServerOption {
return func(o *ServerOptions) {
o.OnlyTCP = true
}
}
func WithName(name string) ServerOption {
return func(o *ServerOptions) {
o.Name = name
}
}
func WithIPVersion(ipVersion string) ServerOption {
return func(o *ServerOptions) {
o.IPVersion = ipVersion
}
}
func WithIP(ip string) ServerOption {
return func(o *ServerOptions) {
o.IP = ip
}
}
func WithPort(port int) ServerOption {
return func(o *ServerOptions) {
o.Port = port
}
}
func WithWebSocketPort(webSocketPort int) ServerOption {
return func(o *ServerOptions) {
o.WebSocketPort = webSocketPort
}
}
func WithWebSocketPath(webSocketPath string) ServerOption {
return func(o *ServerOptions) {
o.WebSocketPath = webSocketPath
}
}
func WithCertFile(certFile string) ServerOption {
return func(o *ServerOptions) {
o.CertFile = certFile
}
}
func WithPrivateKeyFile(privateKeyFile string) ServerOption {
return func(o *ServerOptions) {
o.PrivateKeyFile = privateKeyFile
}
}
func WithMaxConnectionsCount(maxConnectionsCount int) ServerOption {
return func(o *ServerOptions) {
o.MaxConnectionsCount = maxConnectionsCount
}
}
func WithConnectionGroupsCount(connectionGroupsCount int) ServerOption {
return func(o *ServerOptions) {
o.ConnectionGroupsCount = connectionGroupsCount
}
}
func WithConnectionReadBufferSize(connectionReadBufferSize uint32) ServerOption {
return func(o *ServerOptions) {
o.ConnectionReadBufferSize = connectionReadBufferSize
}
}
func WithConnectionWriteBufferSize(connectionWriteBufferSize uint32) ServerOption {
return func(o *ServerOptions) {
o.ConnectionWriteBufferSize = connectionWriteBufferSize
}
}
func WithMaxWorkerTasksCount(maxTasksCount uint32) ServerOption {
return func(o *ServerOptions) {
o.MaxWorkerTasksCount = maxTasksCount
}
}
func WithHeartbeatInterval(heartbeatInterval time.Duration) ServerOption {
return func(o *ServerOptions) {
o.HeartbeatInterval = heartbeatInterval
}
}
func WithHeartbeatTimeout(heartbeatTimeout time.Duration) ServerOption {
return func(o *ServerOptions) {
o.HeartbeatTimeout = heartbeatTimeout
}
}