-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
58 lines (49 loc) · 1.23 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
package eemqtt
import (
"crypto/tls"
"github.com/eclipse/paho.golang/paho"
)
type Option func(c *Container)
//WithWillMessage 使用遗嘱消息
func WithWillMessage(topic string, payload []byte, qos byte, retain bool) Option {
return func(c *Container) {
c.config.enableWillMessage = true
c.config.willTopic = topic
c.config.willPayload = payload
c.config.willQos = qos
c.config.willRetain = retain
}
}
func WithConnectPacketConfigurator(fn func(*paho.Connect) *paho.Connect) Option {
return func(c *Container) {
c.config.enableConnectPacket = true
c.config.connectPacketBuilder = fn
}
}
//WithTLSConfig 自定义tls 验证配置
func WithTLSConfig(tsc *tls.Config) Option {
return func(c *Container) {
c.config.EnableTLS = true
c.config.customizeTlsConfig = tsc
}
}
func WithTLSSessionCache(tsc tls.ClientSessionCache) Option {
return func(c *Container) {
c.config.TLSSessionCache = tsc
}
}
func WithClientID(clientID string) Option {
return func(c *Container) {
c.config.ClientID = clientID
}
}
func WithUsername(username string) Option {
return func(c *Container) {
c.config.Username = username
}
}
func WithPassword(password string) Option {
return func(c *Container) {
c.config.Password = password
}
}