-
Notifications
You must be signed in to change notification settings - Fork 0
/
statusonline.go
59 lines (51 loc) · 1.63 KB
/
statusonline.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
/**
* Created by GoLand.
* User: 姜伟
* Date: 2020/2/1 0001
* Time: 23:31
*/
package client
import (
"regexp"
"github.com/a07061625/gompf/mpf/api/mpiot"
"github.com/a07061625/gompf/mpf/mpconstant/errorcode"
"github.com/a07061625/gompf/mpf/mpconstant/project"
"github.com/a07061625/gompf/mpf/mperr"
"github.com/valyala/fasthttp"
)
// 获取指定MQTT客户端在线状态
type statusOnline struct {
mpiot.BaseBaiDu
endpointName string // endpoint名称
clientId string // 客户端ID
}
func (so *statusOnline) SetEndpointName(endpointName string) {
match, _ := regexp.MatchString(project.RegexDigitAlpha, endpointName)
if match {
so.endpointName = endpointName
} else {
panic(mperr.NewIotBaiDu(errorcode.IotBaiDuParam, "endpoint名称不合法", nil))
}
}
func (so *statusOnline) SetClientId(clientId string) {
if len(clientId) > 0 {
so.clientId = clientId
} else {
panic(mperr.NewIotBaiDu(errorcode.IotBaiDuParam, "客户端ID不合法", nil))
}
}
func (so *statusOnline) CheckData() (*fasthttp.Client, *fasthttp.Request) {
if len(so.endpointName) == 0 {
panic(mperr.NewIotBaiDu(errorcode.IotBaiDuParam, "endpoint名称不能为空", nil))
}
if len(so.clientId) == 0 {
panic(mperr.NewIotBaiDu(errorcode.IotBaiDuParam, "客户端ID不能为空", nil))
}
so.ServiceUri = "/v2/endpoint/" + so.endpointName + "/client/" + so.clientId + "/status/online"
so.ReqURI = so.GetServiceUrl()
return so.GetRequest()
}
func NewStatusOnline() *statusOnline {
so := &statusOnline{mpiot.NewBaseBaiDu(), "", ""}
return so
}