Skip to content

Commit 0f7e4e6

Browse files
committed
Enable more linters
1 parent d8a91de commit 0f7e4e6

File tree

3 files changed

+100
-89
lines changed

3 files changed

+100
-89
lines changed

.golangci.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ linters-settings:
2828
- name: unused-parameter
2929
- name: var-declaration
3030
- name: var-naming
31+
govet:
32+
check-shadowing: true
33+
enable-all: true
3134

3235
linters:
33-
enable:
36+
enable:
3437
- asciicheck
38+
- bidichk
39+
- dupword
3540
- errcheck
3641
- errorlint
3742
- gofmt
@@ -45,15 +50,21 @@ linters:
4550
- misspell
4651
- nilerr
4752
- noctx
53+
- perfsprint
4854
- predeclared
55+
- reassign
4956
- revive
5057
- staticcheck
58+
- tagalign
59+
- tparallel
5160
- typecheck
5261
- unconvert
5362
- unparam
5463
- unused
64+
- usestdlibvars
5565
- wastedassign
56-
disable-all: true
66+
- whitespace
67+
disable-all: true
5768
issues:
5869
max-issues-per-linter: 0
5970
max-same-issues: 0

.pre-commit-config.yaml

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4-
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.5.0
6-
hooks:
7-
- id: trailing-whitespace
8-
- id: end-of-file-fixer
9-
- id: check-yaml
10-
args: [--allow-multiple-documents]
11-
- id: check-added-large-files
12-
- id: check-merge-conflict
13-
- id: check-shebang-scripts-are-executable
14-
- id: check-case-conflict
15-
- id: check-vcs-permalinks
16-
- id: mixed-line-ending
17-
args: [--fix=lf]
18-
- id: no-commit-to-branch
19-
- id: fix-byte-order-marker
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.5.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
args: [--allow-multiple-documents]
11+
- id: check-added-large-files
12+
- id: check-merge-conflict
13+
- id: check-shebang-scripts-are-executable
14+
- id: check-case-conflict
15+
- id: check-vcs-permalinks
16+
- id: mixed-line-ending
17+
args: [--fix=lf]
18+
- id: no-commit-to-branch
19+
- id: fix-byte-order-marker
2020

21-
- repo: local
22-
hooks:
23-
- id: golang-diff
24-
name: create-go-diff
25-
entry: bash -c 'git diff -p origin/main > /tmp/diff.patch'
26-
language: system
27-
types: [go]
28-
pass_filenames: false
21+
- repo: local
22+
hooks:
23+
- id: golang-diff
24+
name: create-go-diff
25+
entry: bash -c 'git diff -p origin/main > /tmp/diff.patch'
26+
language: system
27+
types: [go]
28+
pass_filenames: false
2929

30-
- repo: https://github.com/golangci/golangci-lint
31-
rev: v1.55.2
32-
hooks:
33-
- id: golangci-lint
34-
args: [--new-from-patch=/tmp/diff.patch]
30+
- repo: https://github.com/golangci/golangci-lint
31+
rev: v1.55.2
32+
hooks:
33+
- id: golangci-lint
34+
args: [--new-from-patch=/tmp/diff.patch]
3535

36-
- repo: https://github.com/gitleaks/gitleaks
37-
rev: v8.18.2
38-
hooks:
39-
- id: gitleaks
36+
- repo: https://github.com/gitleaks/gitleaks
37+
rev: v8.18.2
38+
hooks:
39+
- id: gitleaks
4040

41-
- repo: https://github.com/DavidAnson/markdownlint-cli2
42-
rev: v0.12.1
43-
hooks:
44-
- id: markdownlint-cli2
41+
- repo: https://github.com/DavidAnson/markdownlint-cli2
42+
rev: v0.12.1
43+
hooks:
44+
- id: markdownlint-cli2
4545

4646
ci:
4747
skip: [golang-diff, golangci-lint]

client/nginx.go

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ var ErrUnsupportedVer = errors.New("API version of the client is not supported b
4242

4343
// NginxClient lets you access NGINX Plus API.
4444
type NginxClient struct {
45-
apiVersion int
46-
apiEndpoint string
4745
httpClient *http.Client
46+
apiEndpoint string
47+
apiVersion int
4848
checkAPI bool
4949
}
5050

@@ -54,38 +54,38 @@ type versions []int
5454

5555
// UpstreamServer lets you configure HTTP upstreams.
5656
type UpstreamServer struct {
57-
ID int `json:"id,omitempty"`
58-
Server string `json:"server"`
5957
MaxConns *int `json:"max_conns,omitempty"`
6058
MaxFails *int `json:"max_fails,omitempty"`
61-
FailTimeout string `json:"fail_timeout,omitempty"`
62-
SlowStart string `json:"slow_start,omitempty"`
63-
Route string `json:"route,omitempty"`
6459
Backup *bool `json:"backup,omitempty"`
6560
Down *bool `json:"down,omitempty"`
66-
Drain bool `json:"drain,omitempty"`
6761
Weight *int `json:"weight,omitempty"`
62+
Server string `json:"server"`
63+
FailTimeout string `json:"fail_timeout,omitempty"`
64+
SlowStart string `json:"slow_start,omitempty"`
65+
Route string `json:"route,omitempty"`
6866
Service string `json:"service,omitempty"`
67+
ID int `json:"id,omitempty"`
68+
Drain bool `json:"drain,omitempty"`
6969
}
7070

7171
// StreamUpstreamServer lets you configure Stream upstreams.
7272
type StreamUpstreamServer struct {
73-
ID int `json:"id,omitempty"`
74-
Server string `json:"server"`
7573
MaxConns *int `json:"max_conns,omitempty"`
7674
MaxFails *int `json:"max_fails,omitempty"`
77-
FailTimeout string `json:"fail_timeout,omitempty"`
78-
SlowStart string `json:"slow_start,omitempty"`
7975
Backup *bool `json:"backup,omitempty"`
8076
Down *bool `json:"down,omitempty"`
8177
Weight *int `json:"weight,omitempty"`
78+
Server string `json:"server"`
79+
FailTimeout string `json:"fail_timeout,omitempty"`
80+
SlowStart string `json:"slow_start,omitempty"`
8281
Service string `json:"service,omitempty"`
82+
ID int `json:"id,omitempty"`
8383
}
8484

8585
type apiErrorResponse struct {
86-
Error apiError
8786
RequestID string `json:"request_id"`
8887
Href string
88+
Error apiError
8989
}
9090

9191
func (resp *apiErrorResponse) toString() string {
@@ -94,14 +94,14 @@ func (resp *apiErrorResponse) toString() string {
9494
}
9595

9696
type apiError struct {
97-
Status int
9897
Text string
9998
Code string
99+
Status int
100100
}
101101

102102
type internalError struct {
103-
apiError
104103
err string
104+
apiError
105105
}
106106

107107
// Error allows internalError to match the Error interface.
@@ -119,34 +119,34 @@ func (internalError *internalError) Wrap(err string) *internalError {
119119
// Stats represents NGINX Plus stats fetched from the NGINX Plus API.
120120
// https://nginx.org/en/docs/http/ngx_http_api_module.html
121121
type Stats struct {
122-
NginxInfo NginxInfo
123-
Caches Caches
124-
Processes Processes
125-
Connections Connections
126-
Slabs Slabs
127-
HTTPRequests HTTPRequests
128-
SSL SSL
129-
ServerZones ServerZones
130122
Upstreams Upstreams
123+
ServerZones ServerZones
131124
StreamServerZones StreamServerZones
132125
StreamUpstreams StreamUpstreams
133-
StreamZoneSync *StreamZoneSync
134-
LocationZones LocationZones
135-
Resolvers Resolvers
136-
HTTPLimitRequests HTTPLimitRequests
126+
Slabs Slabs
127+
Caches Caches
137128
HTTPLimitConnections HTTPLimitConnections
138129
StreamLimitConnections StreamLimitConnections
130+
HTTPLimitRequests HTTPLimitRequests
131+
Resolvers Resolvers
132+
LocationZones LocationZones
133+
StreamZoneSync *StreamZoneSync
139134
Workers []*Workers
135+
NginxInfo NginxInfo
136+
SSL SSL
137+
Connections Connections
138+
HTTPRequests HTTPRequests
139+
Processes Processes
140140
}
141141

142142
// NginxInfo contains general information about NGINX Plus.
143143
type NginxInfo struct {
144144
Version string
145145
Build string
146146
Address string
147-
Generation uint64
148147
LoadTimestamp string `json:"load_timestamp"`
149148
Timestamp string
149+
Generation uint64
150150
ProcessID uint64 `json:"pid"`
151151
ParentProcessID uint64 `json:"ppid"`
152152
}
@@ -194,8 +194,8 @@ type Slabs map[string]Slab
194194

195195
// Slab represents slab related stats.
196196
type Slab struct {
197-
Pages Pages
198197
Slots Slots
198+
Pages Pages
199199
}
200200

201201
// Pages represents the slab memory usage stats.
@@ -358,21 +358,21 @@ type Upstreams map[string]Upstream
358358

359359
// Upstream represents upstream related stats.
360360
type Upstream struct {
361+
Zone string
361362
Peers []Peer
363+
Queue Queue
362364
Keepalives int
363365
Zombies int
364-
Zone string
365-
Queue Queue
366366
}
367367

368368
// StreamUpstreams is a map of stream upstream stats by upstream name.
369369
type StreamUpstreams map[string]StreamUpstream
370370

371371
// StreamUpstream represents stream upstream related stats.
372372
type StreamUpstream struct {
373+
Zone string
373374
Peers []StreamPeer
374375
Zombies int
375-
Zone string
376376
}
377377

378378
// Queue represents queue related stats for an upstream.
@@ -384,54 +384,54 @@ type Queue struct {
384384

385385
// Peer represents peer (upstream server) related stats.
386386
type Peer struct {
387-
ID int
388387
Server string
389388
Service string
390389
Name string
391-
Backup bool
392-
Weight int
390+
Selected string
391+
Downstart string
393392
State string
394-
Active uint64
393+
Responses Responses
395394
SSL SSL
396-
MaxConns int `json:"max_conns"`
395+
HealthChecks HealthChecks `json:"health_checks"`
397396
Requests uint64
398-
Responses Responses
397+
ID int
398+
MaxConns int `json:"max_conns"`
399399
Sent uint64
400400
Received uint64
401401
Fails uint64
402402
Unavail uint64
403-
HealthChecks HealthChecks `json:"health_checks"`
403+
Active uint64
404404
Downtime uint64
405-
Downstart string
406-
Selected string
405+
Weight int
407406
HeaderTime uint64 `json:"header_time"`
408407
ResponseTime uint64 `json:"response_time"`
408+
Backup bool
409409
}
410410

411411
// StreamPeer represents peer (stream upstream server) related stats.
412412
type StreamPeer struct {
413-
ID int
414413
Server string
415414
Service string
416415
Name string
417-
Backup bool
418-
Weight int
416+
Selected string
417+
Downstart string
419418
State string
420-
Active uint64
421419
SSL SSL
422-
MaxConns int `json:"max_conns"`
420+
HealthChecks HealthChecks `json:"health_checks"`
423421
Connections uint64
422+
Received uint64
423+
ID int
424424
ConnectTime int `json:"connect_time"`
425425
FirstByteTime int `json:"first_byte_time"`
426426
ResponseTime uint64 `json:"response_time"`
427427
Sent uint64
428-
Received uint64
428+
MaxConns int `json:"max_conns"`
429429
Fails uint64
430430
Unavail uint64
431-
HealthChecks HealthChecks `json:"health_checks"`
431+
Active uint64
432432
Downtime uint64
433-
Downstart string
434-
Selected string
433+
Weight int
434+
Backup bool
435435
}
436436

437437
// HealthChecks represents health check related stats for a peer.

0 commit comments

Comments
 (0)