-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_opts.go
32 lines (26 loc) · 871 Bytes
/
client_opts.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
package gkpxc
import "net"
type clientConfig struct {
customConn net.Conn
errorHandlers []func(err error)
lockChangeHandlers []func(locked bool)
}
type ClientOption func(o *clientConfig)
// WithConn sets custom connection for client. It will not be closed by Client.Close.
func WithConn(conn net.Conn) ClientOption {
return func(o *clientConfig) {
o.customConn = conn
}
}
// WithAsyncErrorHandler adds async error handler. Such errors may occur on signal read.
func WithAsyncErrorHandler(handler func(err error)) ClientOption {
return func(o *clientConfig) {
o.errorHandlers = append(o.errorHandlers, handler)
}
}
// WithLockChangeHandler adds lock/unlock signal handler.
func WithLockChangeHandler(handler func(locked bool)) ClientOption {
return func(o *clientConfig) {
o.lockChangeHandlers = append(o.lockChangeHandlers, handler)
}
}