-
Notifications
You must be signed in to change notification settings - Fork 3
/
unifi.go
56 lines (45 loc) · 1.2 KB
/
unifi.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
package main
import (
"fmt"
)
type unifiRequestLogin struct {
Username string `json:"username"`
Password string `json:"password"`
}
type unifiRequestStamgr struct {
Cmd string `json:"cmd"`
Macs []string `json:"macs"`
}
type unifiResponseLogin struct {
UniqueId string `json:"unique_id"`
}
type unifiResponseBase struct {
Meta unifiResponseBaseMeta
}
type unifiResponseBaseMeta struct {
Rc string
Msg string
}
type unifiResponseAllUser struct {
Meta unifiResponseBaseMeta
Data []unifiResponseAllUserClient
}
type unifiResponseAllUserClient struct {
Name string
Mac string
TxBytes int `json:"tx_bytes"`
TxPackets int `json:"tx_packets"`
RxBytes int `json:"rx_bytes"`
RxPackets int `json:"rx_packets"`
WifiTxAttempts int `json:"wifi_tx_attempts"`
TxRetries int `json:"tx_retries"`
}
func unifiResponseCheckMeta(u unifiResponseBaseMeta, responseBody []byte, identifier string) error {
if u.Rc == "error" {
return fmt.Errorf("%s %s %s %s", "Error in UniFi", identifier, "response:", u.Msg)
}
if u.Rc != "ok" {
return fmt.Errorf("%s %s %s %s", "Error with unexpected UniFi", identifier, "response:", string(responseBody))
}
return nil
}