From 56fb59a164083f0da5da011c5f92d8b0940b033d Mon Sep 17 00:00:00 2001 From: Luca Comellini Date: Fri, 2 Feb 2024 20:04:21 -0800 Subject: [PATCH] Enable more linters --- .golangci.yml | 15 +++++++- client/nginx.go | 100 ++++++++++++++++++++++++------------------------ 2 files changed, 63 insertions(+), 52 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5b59549e..8474d339 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -28,10 +28,15 @@ linters-settings: - name: unused-parameter - name: var-declaration - name: var-naming + govet: + check-shadowing: true + enable-all: true linters: - enable: + enable: - asciicheck + - bidichk + - dupword - errcheck - errorlint - gofmt @@ -45,15 +50,21 @@ linters: - misspell - nilerr - noctx + - perfsprint - predeclared + - reassign - revive - staticcheck + - tagalign + - tparallel - typecheck - unconvert - unparam - unused + - usestdlibvars - wastedassign - disable-all: true + - whitespace + disable-all: true issues: max-issues-per-linter: 0 max-same-issues: 0 diff --git a/client/nginx.go b/client/nginx.go index 5c01a40c..41bb77be 100644 --- a/client/nginx.go +++ b/client/nginx.go @@ -42,9 +42,9 @@ var ErrUnsupportedVer = errors.New("API version of the client is not supported b // NginxClient lets you access NGINX Plus API. type NginxClient struct { - apiVersion int - apiEndpoint string httpClient *http.Client + apiEndpoint string + apiVersion int checkAPI bool } @@ -54,38 +54,38 @@ type versions []int // UpstreamServer lets you configure HTTP upstreams. type UpstreamServer struct { - ID int `json:"id,omitempty"` - Server string `json:"server"` MaxConns *int `json:"max_conns,omitempty"` MaxFails *int `json:"max_fails,omitempty"` - FailTimeout string `json:"fail_timeout,omitempty"` - SlowStart string `json:"slow_start,omitempty"` - Route string `json:"route,omitempty"` Backup *bool `json:"backup,omitempty"` Down *bool `json:"down,omitempty"` - Drain bool `json:"drain,omitempty"` Weight *int `json:"weight,omitempty"` + Server string `json:"server"` + FailTimeout string `json:"fail_timeout,omitempty"` + SlowStart string `json:"slow_start,omitempty"` + Route string `json:"route,omitempty"` Service string `json:"service,omitempty"` + ID int `json:"id,omitempty"` + Drain bool `json:"drain,omitempty"` } // StreamUpstreamServer lets you configure Stream upstreams. type StreamUpstreamServer struct { - ID int `json:"id,omitempty"` - Server string `json:"server"` MaxConns *int `json:"max_conns,omitempty"` MaxFails *int `json:"max_fails,omitempty"` - FailTimeout string `json:"fail_timeout,omitempty"` - SlowStart string `json:"slow_start,omitempty"` Backup *bool `json:"backup,omitempty"` Down *bool `json:"down,omitempty"` Weight *int `json:"weight,omitempty"` + Server string `json:"server"` + FailTimeout string `json:"fail_timeout,omitempty"` + SlowStart string `json:"slow_start,omitempty"` Service string `json:"service,omitempty"` + ID int `json:"id,omitempty"` } type apiErrorResponse struct { - Error apiError RequestID string `json:"request_id"` Href string + Error apiError } func (resp *apiErrorResponse) toString() string { @@ -94,14 +94,14 @@ func (resp *apiErrorResponse) toString() string { } type apiError struct { - Status int Text string Code string + Status int } type internalError struct { - apiError err string + apiError } // Error allows internalError to match the Error interface. @@ -119,24 +119,24 @@ func (internalError *internalError) Wrap(err string) *internalError { // Stats represents NGINX Plus stats fetched from the NGINX Plus API. // https://nginx.org/en/docs/http/ngx_http_api_module.html type Stats struct { - NginxInfo NginxInfo - Caches Caches - Processes Processes - Connections Connections - Slabs Slabs - HTTPRequests HTTPRequests - SSL SSL - ServerZones ServerZones Upstreams Upstreams + ServerZones ServerZones StreamServerZones StreamServerZones StreamUpstreams StreamUpstreams - StreamZoneSync *StreamZoneSync - LocationZones LocationZones - Resolvers Resolvers - HTTPLimitRequests HTTPLimitRequests + Slabs Slabs + Caches Caches HTTPLimitConnections HTTPLimitConnections StreamLimitConnections StreamLimitConnections + HTTPLimitRequests HTTPLimitRequests + Resolvers Resolvers + LocationZones LocationZones + StreamZoneSync *StreamZoneSync Workers []*Workers + NginxInfo NginxInfo + SSL SSL + Connections Connections + HTTPRequests HTTPRequests + Processes Processes } // NginxInfo contains general information about NGINX Plus. @@ -144,9 +144,9 @@ type NginxInfo struct { Version string Build string Address string - Generation uint64 LoadTimestamp string `json:"load_timestamp"` Timestamp string + Generation uint64 ProcessID uint64 `json:"pid"` ParentProcessID uint64 `json:"ppid"` } @@ -194,8 +194,8 @@ type Slabs map[string]Slab // Slab represents slab related stats. type Slab struct { - Pages Pages Slots Slots + Pages Pages } // Pages represents the slab memory usage stats. @@ -358,11 +358,11 @@ type Upstreams map[string]Upstream // Upstream represents upstream related stats. type Upstream struct { + Zone string Peers []Peer + Queue Queue Keepalives int Zombies int - Zone string - Queue Queue } // StreamUpstreams is a map of stream upstream stats by upstream name. @@ -370,9 +370,9 @@ type StreamUpstreams map[string]StreamUpstream // StreamUpstream represents stream upstream related stats. type StreamUpstream struct { + Zone string Peers []StreamPeer Zombies int - Zone string } // Queue represents queue related stats for an upstream. @@ -384,54 +384,54 @@ type Queue struct { // Peer represents peer (upstream server) related stats. type Peer struct { - ID int Server string Service string Name string - Backup bool - Weight int + Selected string + Downstart string State string - Active uint64 + Responses Responses SSL SSL - MaxConns int `json:"max_conns"` + HealthChecks HealthChecks `json:"health_checks"` Requests uint64 - Responses Responses + ID int + MaxConns int `json:"max_conns"` Sent uint64 Received uint64 Fails uint64 Unavail uint64 - HealthChecks HealthChecks `json:"health_checks"` + Active uint64 Downtime uint64 - Downstart string - Selected string + Weight int HeaderTime uint64 `json:"header_time"` ResponseTime uint64 `json:"response_time"` + Backup bool } // StreamPeer represents peer (stream upstream server) related stats. type StreamPeer struct { - ID int Server string Service string Name string - Backup bool - Weight int + Selected string + Downstart string State string - Active uint64 SSL SSL - MaxConns int `json:"max_conns"` + HealthChecks HealthChecks `json:"health_checks"` Connections uint64 + Received uint64 + ID int ConnectTime int `json:"connect_time"` FirstByteTime int `json:"first_byte_time"` ResponseTime uint64 `json:"response_time"` Sent uint64 - Received uint64 + MaxConns int `json:"max_conns"` Fails uint64 Unavail uint64 - HealthChecks HealthChecks `json:"health_checks"` + Active uint64 Downtime uint64 - Downstart string - Selected string + Weight int + Backup bool } // HealthChecks represents health check related stats for a peer.