forked from DrmagicE/gmqtt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
50 lines (41 loc) · 1.03 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
package gmqtt
import (
"net"
"go.uber.org/zap"
)
type Options func(srv *server)
// WithConfig set the config of the server
func WithConfig(config Config) Options {
return func(srv *server) {
srv.config = config
}
}
// WithTCPListener set tcp listener(s) of the server. Default listen on :1883.
func WithTCPListener(lns ...net.Listener) Options {
return func(srv *server) {
srv.tcpListener = append(srv.tcpListener, lns...)
}
}
// WithWebsocketServer set websocket server(s) of the server.
func WithWebsocketServer(ws ...*WsServer) Options {
return func(srv *server) {
srv.websocketServer = ws
}
}
// WithPlugin set plugin(s) of the server.
func WithPlugin(plugin ...Plugable) Options {
return func(srv *server) {
srv.plugins = append(srv.plugins, plugin...)
}
}
// WithHook set hooks of the server. Notice: WithPlugin() will overwrite hooks.
func WithHook(hooks Hooks) Options {
return func(srv *server) {
srv.hooks = hooks
}
}
func WithLogger(logger *zap.Logger) Options {
return func(srv *server) {
zaplog = logger
}
}