forked from AlexStocks/getty
-
Notifications
You must be signed in to change notification settings - Fork 70
/
options.go
99 lines (82 loc) · 2.2 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
94
95
96
97
98
99
/******************************************************
# DESC : getty client/server options
# AUTHOR : Alex Stocks
# VERSION : 1.0
# LICENCE : Apache License 2.0
# EMAIL : alexstocks@foxmail.com
# MOD : 2018-03-17 21:12
# FILE : options.go
******************************************************/
package getty
/////////////////////////////////////////
// Server Options
/////////////////////////////////////////
type ServerOption func(*ServerOptions)
type ServerOptions struct {
addr string
// websocket
path string
cert string
privateKey string
caCert string
}
// @addr server listen address.
func WithLocalAddress(addr string) ServerOption {
return func(o *ServerOptions) {
o.addr = addr
}
}
// @path: websocket request url path
func WithWebsocketServerPath(path string) ServerOption {
return func(o *ServerOptions) {
o.path = path
}
}
// @cert: server certificate file
func WithWebsocketServerCert(cert string) ServerOption {
return func(o *ServerOptions) {
o.cert = cert
}
}
// @key: server private key(contains its public key)
func WithWebsocketServerPrivateKey(key string) ServerOption {
return func(o *ServerOptions) {
o.privateKey = key
}
}
// @cert is the root certificate file to verify the legitimacy of server
func WithWebsocketServerRootCert(cert string) ServerOption {
return func(o *ServerOptions) {
o.caCert = cert
}
}
/////////////////////////////////////////
// Client Options
/////////////////////////////////////////
type ClientOption func(*ClientOptions)
type ClientOptions struct {
addr string
number int
// the cert file of wss server which may contain server domain, server ip, the starting effective date, effective
// duration, the hash alg, the len of the private key.
// wss client will use it.
cert string
}
// @addr is server address.
func WithServerAddress(addr string) ClientOption {
return func(o *ClientOptions) {
o.addr = addr
}
}
// @num is connection number.
func WithConnectionNumber(num int) ClientOption {
return func(o *ClientOptions) {
o.number = num
}
}
// @cert is client certificate file. it can be empty.
func WithRootCertificateFile(cert string) ClientOption {
return func(o *ClientOptions) {
o.cert = cert
}
}