3737 defaultWeight = 1
3838)
3939
40- // ErrUnsupportedVer means that client's API version is not supported by NGINX plus API
40+ // ErrUnsupportedVer means that client's API version is not supported by NGINX plus API.
4141var ErrUnsupportedVer = errors .New ("API version of the client is not supported by running NGINX Plus" )
4242
4343// NginxClient lets you access NGINX Plus API.
@@ -151,10 +151,10 @@ type NginxInfo struct {
151151 ParentProcessID uint64 `json:"ppid"`
152152}
153153
154- // Caches is a map of cache stats by cache zone
154+ // Caches is a map of cache stats by cache zone.
155155type Caches = map [string ]HTTPCache
156156
157- // HTTPCache represents a zone's HTTP Cache
157+ // HTTPCache represents a zone's HTTP Cache.
158158type HTTPCache struct {
159159 Size uint64
160160 MaxSize uint64 `json:"max_size"`
@@ -204,7 +204,7 @@ type Pages struct {
204204 Free uint64
205205}
206206
207- // Slots is a map of slots by slot size
207+ // Slots is a map of slots by slot size.
208208type Slots map [string ]Slot
209209
210210// Slot represents slot related stats.
@@ -241,7 +241,7 @@ type VerifyFailures struct {
241241 Other uint64 `json:"other"`
242242}
243243
244- // ServerZones is map of server zone stats by zone name
244+ // ServerZones is map of server zone stats by zone name.
245245type ServerZones map [string ]ServerZone
246246
247247// ServerZone represents server zone related stats.
@@ -269,19 +269,19 @@ type StreamServerZone struct {
269269 SSL SSL
270270}
271271
272- // StreamZoneSync represents the sync information per each shared memory zone and the sync information per node in a cluster
272+ // StreamZoneSync represents the sync information per each shared memory zone and the sync information per node in a cluster.
273273type StreamZoneSync struct {
274274 Zones map [string ]SyncZone
275275 Status StreamZoneSyncStatus
276276}
277277
278- // SyncZone represents the synchronization status of a shared memory zone
278+ // SyncZone represents the synchronization status of a shared memory zone.
279279type SyncZone struct {
280280 RecordsPending uint64 `json:"records_pending"`
281281 RecordsTotal uint64 `json:"records_total"`
282282}
283283
284- // StreamZoneSyncStatus represents the status of a shared memory zone
284+ // StreamZoneSyncStatus represents the status of a shared memory zone.
285285type StreamZoneSyncStatus struct {
286286 BytesIn uint64 `json:"bytes_in"`
287287 MsgsIn uint64 `json:"msgs_in"`
@@ -301,7 +301,7 @@ type Responses struct {
301301 Total uint64
302302}
303303
304- // HTTPCodes represents HTTP response codes
304+ // HTTPCodes represents HTTP response codes.
305305type HTTPCodes struct {
306306 HTTPContinue uint64 `json:"100,omitempty"`
307307 HTTPSwitchingProtocols uint64 `json:"101,omitempty"`
@@ -442,13 +442,13 @@ type HealthChecks struct {
442442 LastPassed bool `json:"last_passed"`
443443}
444444
445- // LocationZones represents location_zones related stats
445+ // LocationZones represents location_zones related stats.
446446type LocationZones map [string ]LocationZone
447447
448- // Resolvers represents resolvers related stats
448+ // Resolvers represents resolvers related stats.
449449type Resolvers map [string ]Resolver
450450
451- // LocationZone represents location_zones related stats
451+ // LocationZone represents location_zones related stats.
452452type LocationZone struct {
453453 Requests int64
454454 Responses Responses
@@ -457,20 +457,20 @@ type LocationZone struct {
457457 Sent int64
458458}
459459
460- // Resolver represents resolvers related stats
460+ // Resolver represents resolvers related stats.
461461type Resolver struct {
462462 Requests ResolverRequests `json:"requests"`
463463 Responses ResolverResponses `json:"responses"`
464464}
465465
466- // ResolverRequests represents resolver requests
466+ // ResolverRequests represents resolver requests.
467467type ResolverRequests struct {
468468 Name int64
469469 Srv int64
470470 Addr int64
471471}
472472
473- // ResolverResponses represents resolver responses
473+ // ResolverResponses represents resolver responses.
474474type ResolverResponses struct {
475475 Noerror int64
476476 Formerr int64
@@ -482,12 +482,12 @@ type ResolverResponses struct {
482482 Unknown int64
483483}
484484
485- // Processes represents processes related stats
485+ // Processes represents processes related stats.
486486type Processes struct {
487487 Respawned int64
488488}
489489
490- // HTTPLimitRequest represents HTTP Requests Rate Limiting
490+ // HTTPLimitRequest represents HTTP Requests Rate Limiting.
491491type HTTPLimitRequest struct {
492492 Passed uint64
493493 Delayed uint64
@@ -496,31 +496,31 @@ type HTTPLimitRequest struct {
496496 RejectedDryRun uint64 `json:"rejected_dry_run"`
497497}
498498
499- // HTTPLimitRequests represents limit requests related stats
499+ // HTTPLimitRequests represents limit requests related stats.
500500type HTTPLimitRequests map [string ]HTTPLimitRequest
501501
502- // LimitConnection represents Connections Limiting
502+ // LimitConnection represents Connections Limiting.
503503type LimitConnection struct {
504504 Passed uint64
505505 Rejected uint64
506506 RejectedDryRun uint64 `json:"rejected_dry_run"`
507507}
508508
509- // HTTPLimitConnections represents limit connections related stats
509+ // HTTPLimitConnections represents limit connections related stats.
510510type HTTPLimitConnections map [string ]LimitConnection
511511
512- // StreamLimitConnections represents limit connections related stats
512+ // StreamLimitConnections represents limit connections related stats.
513513type StreamLimitConnections map [string ]LimitConnection
514514
515- // Workers represents worker connections related stats
515+ // Workers represents worker connections related stats.
516516type Workers struct {
517517 ID int
518518 ProcessID uint64 `json:"pid"`
519519 HTTP WorkersHTTP `json:"http"`
520520 Connections Connections
521521}
522522
523- // WorkersHTTP represents HTTP worker connections
523+ // WorkersHTTP represents HTTP worker connections.
524524type WorkersHTTP struct {
525525 HTTPRequests HTTPRequests `json:"requests"`
526526}
@@ -725,7 +725,7 @@ func (client *NginxClient) UpdateHTTPServers(upstream string, servers []Upstream
725725 }
726726
727727 // We assume port 80 if no port is set for servers.
728- var formattedServers []UpstreamServer
728+ formattedServers := make ( []UpstreamServer , 0 , len ( servers ))
729729 for _ , server := range servers {
730730 server .Server = addPortToServer (server .Server )
731731 formattedServers = append (formattedServers , server )
@@ -757,7 +757,7 @@ func (client *NginxClient) UpdateHTTPServers(upstream string, servers []Upstream
757757 return toAdd , toDelete , toUpdate , nil
758758}
759759
760- // haveSameParameters checks if a given server has the same parameters as a server already present in NGINX. Order matters
760+ // haveSameParameters checks if a given server has the same parameters as a server already present in NGINX. Order matters.
761761func haveSameParameters (newServer UpstreamServer , serverNGX UpstreamServer ) bool {
762762 newServer .ID = serverNGX .ID
763763
@@ -1036,7 +1036,7 @@ func (client *NginxClient) UpdateStreamServers(upstream string, servers []Stream
10361036 return nil , nil , nil , fmt .Errorf ("failed to update stream servers of %v upstream: %w" , upstream , err )
10371037 }
10381038
1039- var formattedServers []StreamUpstreamServer
1039+ formattedServers := make ( []StreamUpstreamServer , 0 , len ( servers ))
10401040 for _ , server := range servers {
10411041 server .Server = addPortToServer (server .Server )
10421042 formattedServers = append (formattedServers , server )
@@ -1083,7 +1083,7 @@ func (client *NginxClient) getIDOfStreamServer(upstream string, name string) (in
10831083 return - 1 , nil
10841084}
10851085
1086- // haveSameParametersForStream checks if a given server has the same parameters as a server already present in NGINX. Order matters
1086+ // haveSameParametersForStream checks if a given server has the same parameters as a server already present in NGINX. Order matters.
10871087func haveSameParametersForStream (newServer StreamUpstreamServer , serverNGX StreamUpstreamServer ) bool {
10881088 newServer .ID = serverNGX .ID
10891089 if serverNGX .MaxConns != nil && newServer .MaxConns == nil {
@@ -1330,7 +1330,7 @@ func (client *NginxClient) GetNginxInfo() (*NginxInfo, error) {
13301330 return & info , nil
13311331}
13321332
1333- // GetCaches returns Cache stats
1333+ // GetCaches returns Cache stats.
13341334func (client * NginxClient ) GetCaches () (* Caches , error ) {
13351335 var caches Caches
13361336 err := client .get ("http/caches" , & caches )
0 commit comments