Skip to content

Commit cb0eebf

Browse files
Merge pull request #91 from unpoller/linting
Apply Linting, Improve Release Process
2 parents 1203f11 + 637233d commit cb0eebf

26 files changed

+530
-312
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Build
22

3-
on:
3+
on:
44
- pull_request
55

66
permissions:
@@ -14,8 +14,8 @@ jobs:
1414
test:
1515
strategy:
1616
matrix:
17-
go: [1.19]
18-
os: [ubuntu-latest]
17+
go: ["1.20"]
18+
os: [ubuntu-latest, macos-latest]
1919
runs-on: ${{ matrix.os }}
2020
steps:
2121
- uses: actions/checkout@v3
@@ -33,7 +33,7 @@ jobs:
3333
lint:
3434
strategy:
3535
matrix:
36-
go: [1.19]
36+
go: ["1.20"]
3737
os: [ubuntu-latest]
3838
name: lint
3939
runs-on: ${{ matrix.os }}
@@ -47,13 +47,4 @@ jobs:
4747
uses: golangci/golangci-lint-action@v3
4848
with:
4949
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
50-
version: v1.50.1
51-
# Optional: working directory, useful for monorepos
52-
# working-directory: somedir
53-
54-
# Optional: golangci-lint command line arguments.
55-
# args: --issues-exit-code=0
56-
args: --timeout=3m
57-
58-
# Optional: show only new issues if it's a pull request. The default value is `false`.
59-
# only-new-issues: true
50+
version: v1.53

.github/workflows/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
# run only against tags
6+
tags:
7+
- '*'
8+
9+
permissions:
10+
contents: write
11+
packages: write
12+
13+
jobs:
14+
release:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
- run: git fetch --force --tags
21+
- uses: actions/setup-go@v3
22+
with:
23+
go-version: '>=1.20.5'
24+
cache: true
25+
- uses: goreleaser/goreleaser-action@v4
26+
with:
27+
# either 'goreleaser' (default) or 'goreleaser-pro':
28+
distribution: goreleaser-pro
29+
version: latest
30+
args: release --clean
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro'
34+
# distribution:
35+
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}

.golangci.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
run:
2+
timeout: 3m
3+
4+
linters:
5+
enable:
6+
- wsl
7+
- nlreturn
8+
- tagalign
9+
- revive
10+
- testpackage
11+
- errcheck
12+
- gosimple
13+
- govet
14+
- ineffassign
15+
- staticcheck
16+
- unused
17+
18+
output:
19+
sort-results: true
20+
21+
issues:
22+
# disable the default limit so we see everything
23+
max-same-issues: 0
24+
max-issues-per-linter: 0
25+
26+
# default enable fix where the linter supports
27+
fix: true

.goreleaser.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
builds:
2+
- skip: true

alarms.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,44 @@ import (
88

99
type Alarm struct {
1010
Archived FlexBool `json:"archived"`
11-
DestPort int `json:"dest_port" fake:"{port}"`
12-
SrcPort int `json:"src_port" fake:"{port}"`
11+
DestPort int `fake:"{port}" json:"dest_port"`
12+
SrcPort int `fake:"{port}" json:"src_port"`
1313
FlowID int64 `json:"flow_id"`
1414
InnerAlertGID int64 `json:"inner_alert_gid"`
1515
InnerAlertRev int64 `json:"inner_alert_rev"`
1616
InnerAlertSeverity int64 `json:"inner_alert_severity"`
1717
InnerAlertSignatureID int64 `json:"inner_alert_signature_id"`
18-
Time int64 `json:"time" fake:"{timestamp}"`
19-
Timestamp int64 `json:"timestamp" fake:"{timestamp}"`
18+
Time int64 `fake:"{timestamp}" json:"time"`
19+
Timestamp int64 `fake:"{timestamp}" json:"timestamp"`
2020
Datetime time.Time `json:"datetime"`
2121
HandledTime time.Time `json:"handled_time,omitempty"`
2222
AppProto string `json:"app_proto,omitempty"`
2323
Catname string `json:"catname"`
24-
DestIP string `json:"dest_ip" fake:"{ipv4address}"`
25-
DstMAC string `json:"dst_mac" fake:"{macaddress}"`
24+
DestIP string `fake:"{ipv4address}" json:"dest_ip"`
25+
DstMAC string `fake:"{macaddress}" json:"dst_mac"`
2626
DstIPASN string `json:"dstipASN,omitempty"`
2727
DstIPCountry string `json:"dstipCountry,omitempty"`
2828
EventType string `json:"event_type"`
2929
HandledAdminID string `json:"handled_admin_id,omitempty"`
3030
Host string `json:"host"`
31-
ID string `json:"_id" fake:"{uuid}"`
32-
InIface string `json:"in_iface" fake:"{randomstring:[eth0,eth1,lan1,wan1,wan2]}"`
31+
ID string `fake:"{uuid}" json:"_id"`
32+
InIface string `fake:"{randomstring:[eth0,eth1,lan1,wan1,wan2]}" json:"in_iface"`
3333
InnerAlertAction string `json:"inner_alert_action"`
3434
InnerAlertCategory string `json:"inner_alert_category"`
3535
InnerAlertSignature string `json:"inner_alert_signature"`
3636
Key string `json:"key"`
37-
Msg string `json:"msg" fake:"{sentence:5}"`
37+
Msg string `fake:"{sentence:5}" json:"msg"`
3838
Proto string `json:"proto"`
39-
SiteID string `json:"site_id" fake:"{uuid}"`
39+
SiteID string `fake:"{uuid}" json:"site_id"`
4040
SiteName string `json:"-"`
4141
SourceName string `json:"-"`
42-
SrcIP string `json:"src_ip" fake:"{ipv4address}"`
42+
SrcIP string `fake:"{ipv4address}" json:"src_ip"`
4343
SrcIPASN string `json:"srcipASN,omitempty"`
4444
SrcIPCountry string `json:"srcipCountry,omitempty"`
45-
SrcMAC string `json:"src_mac" fake:"{macaddress}"`
45+
SrcMAC string `fake:"{macaddress}" json:"src_mac"`
4646
Subsystem string `json:"subsystem"`
4747
UniqueAlertID string `json:"unique_alertid"`
48-
USGIP string `json:"usgip" fake:"{ipv4address}"`
48+
USGIP string `fake:"{ipv4address}" json:"usgip"`
4949
USGIPASN string `json:"usgipASN"`
5050
USGIPCountry string `json:"usgipCountry"`
5151
TxID FlexInt `json:"tx_id,omitempty"`

anomalies.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
// anomaly is the type UniFi returns, but not the type this library returns.
1212
type anomaly struct {
1313
Anomaly string `json:"anomaly"`
14-
MAC string `json:"mac" fake:"{macaddress}"`
15-
Timestamps []int64 `json:"timestamps" fake:"{timestamps}"`
14+
MAC string `fake:"{macaddress}" json:"mac"`
15+
Timestamps []int64 `fake:"{timestamps}" json:"timestamps"`
1616
}
1717

1818
// Anomaly is the reformatted data type that this library returns.

clients.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ func (u *Unifi) GetClientsDPI(sites []*Site) ([]*DPITable, error) {
6767
type Client struct {
6868
SourceName string `json:"-"`
6969
Anomalies FlexInt `json:"anomalies,omitempty"`
70-
ApMac string `json:"ap_mac" fake:"{macaddress}"`
70+
ApMac string `fake:"{macaddress}" json:"ap_mac"`
7171
ApName string `json:"-"`
7272
AssocTime FlexInt `json:"assoc_time"`
7373
Blocked bool `json:"blocked,omitempty"`
74-
Bssid string `json:"bssid" fake:"{macaddress}"`
74+
Bssid string `fake:"{macaddress}" json:"bssid"`
7575
BytesR FlexInt `json:"bytes-r"`
7676
Ccq FlexInt `json:"ccq"`
7777
Channel FlexInt `json:"channel"`
@@ -81,14 +81,14 @@ type Client struct {
8181
DevVendor FlexInt `json:"dev_vendor,omitempty"`
8282
DhcpendTime FlexInt `json:"dhcpend_time,omitempty"`
8383
Satisfaction FlexInt `json:"satisfaction,omitempty"`
84-
Essid string `json:"essid" fake:"{macaddress}"`
84+
Essid string `fake:"{macaddress}" json:"essid"`
8585
FirstSeen FlexInt `json:"first_seen"`
86-
FixedIP string `json:"fixed_ip" fake:"{ipv4address}"`
87-
GwMac string `json:"gw_mac" fake:"{macaddress}"`
86+
FixedIP string `fake:"{ipv4address}" json:"fixed_ip"`
87+
GwMac string `fake:"{macaddress}" json:"gw_mac"`
8888
GwName string `json:"-"`
8989
Hostname string `json:"hostname"`
90-
ID string `json:"_id" fake:"{uuid}"`
91-
IP string `json:"ip" fake:"{ipv4address}"`
90+
ID string `fake:"{uuid}" json:"_id"`
91+
IP string `fake:"{ipv4address}" json:"ip"`
9292
IdleTime FlexInt `json:"idle_time"`
9393
Is11R FlexBool `json:"is_11r"`
9494
IsGuest FlexBool `json:"is_guest"`
@@ -101,12 +101,12 @@ type Client struct {
101101
LastSeenByUGW FlexInt `json:"_last_seen_by_ugw"`
102102
LastSeenByUSW FlexInt `json:"_last_seen_by_usw"`
103103
LatestAssocTime FlexInt `json:"latest_assoc_time"`
104-
Mac string `json:"mac" fake:"{macaddress}"`
104+
Mac string `fake:"{macaddress}" json:"mac"`
105105
Name string `json:"name"`
106106
Network string `json:"network"`
107-
NetworkID string `json:"network_id" fake:"{uuid}"`
107+
NetworkID string `fake:"{uuid}" json:"network_id"`
108108
Noise FlexInt `json:"noise"`
109-
Note string `json:"note" fake:"{sentence 20}"`
109+
Note string `fake:"{sentence 20}" json:"note"`
110110
Noted FlexBool `json:"noted"`
111111
OsClass FlexInt `json:"os_class"`
112112
OsName FlexInt `json:"os_name"`
@@ -124,10 +124,10 @@ type Client struct {
124124
RxPackets FlexInt `json:"rx_packets"`
125125
RxRate FlexInt `json:"rx_rate"`
126126
Signal FlexInt `json:"signal"`
127-
SiteID string `json:"site_id" fake:"{uuid}"`
127+
SiteID string `fake:"{uuid}" json:"site_id"`
128128
SiteName string `json:"-"`
129129
SwDepth int `json:"sw_depth"`
130-
SwMac string `json:"sw_mac" fake:"{macaddress}"`
130+
SwMac string `fake:"{macaddress}" json:"sw_mac"`
131131
SwName string `json:"-"`
132132
SwPort FlexInt `json:"sw_port"`
133133
TxBytes FlexInt `json:"tx_bytes"`
@@ -141,8 +141,8 @@ type Client struct {
141141
UptimeByUGW FlexInt `json:"_uptime_by_ugw"`
142142
UptimeByUSW FlexInt `json:"_uptime_by_usw"`
143143
UseFixedIP FlexBool `json:"use_fixedip"`
144-
UserGroupID string `json:"usergroup_id" fake:"{uuid}"`
145-
UserID string `json:"user_id" fake:"{uuid}"`
144+
UserGroupID string `fake:"{uuid}" json:"usergroup_id"`
145+
UserID string `fake:"{uuid}" json:"user_id"`
146146
Vlan FlexInt `json:"vlan"`
147147
WifiTxAttempts FlexInt `json:"wifi_tx_attempts"`
148148
WiredRxBytes FlexInt `json:"wired-rx_bytes"`

devices.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func (u *Unifi) parseDevices(data []json.RawMessage, site *Site) *Devices {
116116
var o minimalUnmarshalInfo
117117
if u.unmarshalDevice("map", r, &o) != nil {
118118
u.ErrorLog("unknown asset type - cannot find asset type in payload - skipping")
119+
119120
continue
120121
}
121122

devmgr.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ const (
2727
// devMgrCmd is the type marshalled and sent to APIDevMgrPath.
2828
type devMgrCmd struct {
2929
Cmd string `json:"cmd"` // Required.
30-
Mac string `json:"mac" fake:"{macaddress}"` // Device MAC (required for most, but not all).
31-
URL string `json:"url,omitempty" fake:"{url}"` // External Upgrade only.
32-
Inform string `json:"inform_url,omitempty" fake:"{url}"` // Migration only.
30+
Mac string `fake:"{macaddress}" json:"mac"` // Device MAC (required for most, but not all).
31+
URL string `fake:"{url}" json:"url,omitempty"` // External Upgrade only.
32+
Inform string `fake:"{url}" json:"inform_url,omitempty"` // Migration only.
3333
Port int `json:"port_idx,omitempty"` // Power Cycle only.
3434
}
3535

@@ -51,6 +51,7 @@ func (s *Site) devMgrCommandReply(cmd *devMgrCmd) ([]byte, error) {
5151
// devMgrCommandSimple is for commands with no return value.
5252
func (s *Site) devMgrCommandSimple(cmd *devMgrCmd) error {
5353
_, err := s.devMgrCommandReply(cmd)
54+
5455
return err
5556
}
5657

dpi.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ type DPITable struct {
77
SourceName string `json:"-"`
88
SiteName string `json:"-"`
99
Name string `json:"-"`
10-
MAC string `json:"mac" fake:"{macaddress}"`
11-
ByCat []DPIData `json:"by_cat" fakesize:"5"`
12-
ByApp []DPIData `json:"by_app" fakesize:"5"`
10+
MAC string `fake:"{macaddress}" json:"mac"`
11+
ByCat []DPIData `fakesize:"5" json:"by_cat"`
12+
ByApp []DPIData `fakesize:"5" json:"by_app"`
1313
LastUpdated FlexInt `json:"last_updated"`
1414
}
1515

@@ -21,13 +21,13 @@ type DPIData struct {
2121
TxBytes FlexInt `json:"tx_bytes"`
2222
RxPackets FlexInt `json:"rx_packets"`
2323
TxPackets FlexInt `json:"tx_packets"`
24-
Clients []*DPIClient `json:"clients,omitempty" fakesize:"5"`
24+
Clients []*DPIClient `fakesize:"5" json:"clients,omitempty"`
2525
KnownClients FlexInt `json:"known_clients,omitempty"`
2626
}
2727

2828
// DPIClient data is sometimes included in ByApp output.
2929
type DPIClient struct {
30-
Mac string `json:"mac" fake:"{macaddress}"`
30+
Mac string `fake:"{macaddress}" json:"mac"`
3131
RxBytes FlexInt `json:"rx_bytes"`
3232
TxBytes FlexInt `json:"tx_bytes"`
3333
RxPackets FlexInt `json:"rx_packets"`

0 commit comments

Comments
 (0)