/
api_option.go
106 lines (89 loc) · 1.99 KB
/
api_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2020 thinkgos (thinkgo@aliyun.com). All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package aiot
import (
"time"
"github.com/things-go/aliyun-iot/logger"
)
// Option 配置选项
type Option func(*Client)
// WithCache 设备消息缓存超时时间
func WithCache(expiration, cleanupInterval time.Duration) Option {
return func(c *Client) {
c.cacheExpiration = expiration
c.cacheCleanupInterval = cleanupInterval
}
}
// WithMode 设置工作模式 支持 ModeCOAP ,ModeHTTP, ModeMQTT(默认)
func WithMode(m Mode) Option {
return func(c *Client) {
c.mode = m
}
}
// WithVersion 设置平台版本,默认为 DefaultVersion
func WithVersion(ver string) Option {
return func(c *Client) {
c.version = ver
}
}
// WithEnableNTP 使能NTP
func WithEnableNTP() Option {
return func(c *Client) {
c.hasNTP = true
}
}
// WithEnableModelRaw 使能透传
func WithEnableModelRaw() Option {
return func(c *Client) {
c.hasRawModel = true
}
}
// WithEnableDesired 使能期望属性
func WithEnableDesired() Option {
return func(c *Client) {
c.hasDesired = true
}
}
// WithEnableExtRRPC 使能扩展RRPC功能
func WithEnableExtRRPC() Option {
return func(c *Client) {
c.hasExtRRPC = true
}
}
// WithEnableGateway 使能网关功能
func WithEnableGateway() Option {
return func(c *Client) {
c.isGateway = true
}
}
// WithEnableOTA 使能ota功能
func WithEnableOTA() Option {
return func(c *Client) {
c.hasOTA = true
}
}
// WithEnableDiag 使能diag功能
func WithEnableDiag() Option {
return func(c *Client) {
c.hasDiag = true
}
}
// WithCallback 设置事件处理接口
func WithCallback(cb Callback) Option {
return func(c *Client) {
c.cb = cb
}
}
// WithGwCallback 设备网关事件接口
func WithGwCallback(cb GwCallback) Option {
return func(c *Client) {
c.gwCb = cb
}
}
// WithLogger 设置日志
func WithLogger(l logger.Logger) Option {
return func(c *Client) {
c.Log = l
}
}