-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
88 lines (71 loc) · 1.6 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
package connector
import (
"crypto/tls"
"net/url"
"time"
"github.com/jxo-me/netx/core/common/net/dialer"
"github.com/jxo-me/netx/core/logger"
)
type Options struct {
Auth *url.Userinfo
TLSConfig *tls.Config
Logger logger.ILogger
}
type Option func(opts *Options)
func AuthOption(auth *url.Userinfo) Option {
return func(opts *Options) {
opts.Auth = auth
}
}
func TLSConfigOption(tlsConfig *tls.Config) Option {
return func(opts *Options) {
opts.TLSConfig = tlsConfig
}
}
func LoggerOption(logger logger.ILogger) Option {
return func(opts *Options) {
opts.Logger = logger
}
}
type ConnectOptions struct {
NetDialer *dialer.NetDialer
}
type ConnectOption func(opts *ConnectOptions)
func NetDialerConnectOption(netd *dialer.NetDialer) ConnectOption {
return func(opts *ConnectOptions) {
opts.NetDialer = netd
}
}
type BindOptions struct {
Mux bool
Backlog int
UDPDataQueueSize int
UDPDataBufferSize int
UDPConnTTL time.Duration
}
type BindOption func(opts *BindOptions)
func MuxBindOption(mux bool) BindOption {
return func(opts *BindOptions) {
opts.Mux = mux
}
}
func BacklogBindOption(backlog int) BindOption {
return func(opts *BindOptions) {
opts.Backlog = backlog
}
}
func UDPDataQueueSizeBindOption(size int) BindOption {
return func(opts *BindOptions) {
opts.UDPDataQueueSize = size
}
}
func UDPDataBufferSizeBindOption(size int) BindOption {
return func(opts *BindOptions) {
opts.UDPDataBufferSize = size
}
}
func UDPConnTTLBindOption(ttl time.Duration) BindOption {
return func(opts *BindOptions) {
opts.UDPConnTTL = ttl
}
}