37
37
defaultWeight = 1
38
38
)
39
39
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.
41
41
var ErrUnsupportedVer = errors .New ("API version of the client is not supported by running NGINX Plus" )
42
42
43
43
// NginxClient lets you access NGINX Plus API.
@@ -151,10 +151,10 @@ type NginxInfo struct {
151
151
ParentProcessID uint64 `json:"ppid"`
152
152
}
153
153
154
- // Caches is a map of cache stats by cache zone
154
+ // Caches is a map of cache stats by cache zone.
155
155
type Caches = map [string ]HTTPCache
156
156
157
- // HTTPCache represents a zone's HTTP Cache
157
+ // HTTPCache represents a zone's HTTP Cache.
158
158
type HTTPCache struct {
159
159
Size uint64
160
160
MaxSize uint64 `json:"max_size"`
@@ -204,7 +204,7 @@ type Pages struct {
204
204
Free uint64
205
205
}
206
206
207
- // Slots is a map of slots by slot size
207
+ // Slots is a map of slots by slot size.
208
208
type Slots map [string ]Slot
209
209
210
210
// Slot represents slot related stats.
@@ -241,7 +241,7 @@ type VerifyFailures struct {
241
241
Other uint64 `json:"other"`
242
242
}
243
243
244
- // ServerZones is map of server zone stats by zone name
244
+ // ServerZones is map of server zone stats by zone name.
245
245
type ServerZones map [string ]ServerZone
246
246
247
247
// ServerZone represents server zone related stats.
@@ -269,19 +269,19 @@ type StreamServerZone struct {
269
269
SSL SSL
270
270
}
271
271
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.
273
273
type StreamZoneSync struct {
274
274
Zones map [string ]SyncZone
275
275
Status StreamZoneSyncStatus
276
276
}
277
277
278
- // SyncZone represents the synchronization status of a shared memory zone
278
+ // SyncZone represents the synchronization status of a shared memory zone.
279
279
type SyncZone struct {
280
280
RecordsPending uint64 `json:"records_pending"`
281
281
RecordsTotal uint64 `json:"records_total"`
282
282
}
283
283
284
- // StreamZoneSyncStatus represents the status of a shared memory zone
284
+ // StreamZoneSyncStatus represents the status of a shared memory zone.
285
285
type StreamZoneSyncStatus struct {
286
286
BytesIn uint64 `json:"bytes_in"`
287
287
MsgsIn uint64 `json:"msgs_in"`
@@ -301,7 +301,7 @@ type Responses struct {
301
301
Total uint64
302
302
}
303
303
304
- // HTTPCodes represents HTTP response codes
304
+ // HTTPCodes represents HTTP response codes.
305
305
type HTTPCodes struct {
306
306
HTTPContinue uint64 `json:"100,omitempty"`
307
307
HTTPSwitchingProtocols uint64 `json:"101,omitempty"`
@@ -442,13 +442,13 @@ type HealthChecks struct {
442
442
LastPassed bool `json:"last_passed"`
443
443
}
444
444
445
- // LocationZones represents location_zones related stats
445
+ // LocationZones represents location_zones related stats.
446
446
type LocationZones map [string ]LocationZone
447
447
448
- // Resolvers represents resolvers related stats
448
+ // Resolvers represents resolvers related stats.
449
449
type Resolvers map [string ]Resolver
450
450
451
- // LocationZone represents location_zones related stats
451
+ // LocationZone represents location_zones related stats.
452
452
type LocationZone struct {
453
453
Requests int64
454
454
Responses Responses
@@ -457,20 +457,20 @@ type LocationZone struct {
457
457
Sent int64
458
458
}
459
459
460
- // Resolver represents resolvers related stats
460
+ // Resolver represents resolvers related stats.
461
461
type Resolver struct {
462
462
Requests ResolverRequests `json:"requests"`
463
463
Responses ResolverResponses `json:"responses"`
464
464
}
465
465
466
- // ResolverRequests represents resolver requests
466
+ // ResolverRequests represents resolver requests.
467
467
type ResolverRequests struct {
468
468
Name int64
469
469
Srv int64
470
470
Addr int64
471
471
}
472
472
473
- // ResolverResponses represents resolver responses
473
+ // ResolverResponses represents resolver responses.
474
474
type ResolverResponses struct {
475
475
Noerror int64
476
476
Formerr int64
@@ -482,12 +482,12 @@ type ResolverResponses struct {
482
482
Unknown int64
483
483
}
484
484
485
- // Processes represents processes related stats
485
+ // Processes represents processes related stats.
486
486
type Processes struct {
487
487
Respawned int64
488
488
}
489
489
490
- // HTTPLimitRequest represents HTTP Requests Rate Limiting
490
+ // HTTPLimitRequest represents HTTP Requests Rate Limiting.
491
491
type HTTPLimitRequest struct {
492
492
Passed uint64
493
493
Delayed uint64
@@ -496,31 +496,31 @@ type HTTPLimitRequest struct {
496
496
RejectedDryRun uint64 `json:"rejected_dry_run"`
497
497
}
498
498
499
- // HTTPLimitRequests represents limit requests related stats
499
+ // HTTPLimitRequests represents limit requests related stats.
500
500
type HTTPLimitRequests map [string ]HTTPLimitRequest
501
501
502
- // LimitConnection represents Connections Limiting
502
+ // LimitConnection represents Connections Limiting.
503
503
type LimitConnection struct {
504
504
Passed uint64
505
505
Rejected uint64
506
506
RejectedDryRun uint64 `json:"rejected_dry_run"`
507
507
}
508
508
509
- // HTTPLimitConnections represents limit connections related stats
509
+ // HTTPLimitConnections represents limit connections related stats.
510
510
type HTTPLimitConnections map [string ]LimitConnection
511
511
512
- // StreamLimitConnections represents limit connections related stats
512
+ // StreamLimitConnections represents limit connections related stats.
513
513
type StreamLimitConnections map [string ]LimitConnection
514
514
515
- // Workers represents worker connections related stats
515
+ // Workers represents worker connections related stats.
516
516
type Workers struct {
517
517
ID int
518
518
ProcessID uint64 `json:"pid"`
519
519
HTTP WorkersHTTP `json:"http"`
520
520
Connections Connections
521
521
}
522
522
523
- // WorkersHTTP represents HTTP worker connections
523
+ // WorkersHTTP represents HTTP worker connections.
524
524
type WorkersHTTP struct {
525
525
HTTPRequests HTTPRequests `json:"requests"`
526
526
}
@@ -725,7 +725,7 @@ func (client *NginxClient) UpdateHTTPServers(upstream string, servers []Upstream
725
725
}
726
726
727
727
// We assume port 80 if no port is set for servers.
728
- var formattedServers []UpstreamServer
728
+ formattedServers := make ( []UpstreamServer , 0 , len ( servers ))
729
729
for _ , server := range servers {
730
730
server .Server = addPortToServer (server .Server )
731
731
formattedServers = append (formattedServers , server )
@@ -757,7 +757,7 @@ func (client *NginxClient) UpdateHTTPServers(upstream string, servers []Upstream
757
757
return toAdd , toDelete , toUpdate , nil
758
758
}
759
759
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.
761
761
func haveSameParameters (newServer UpstreamServer , serverNGX UpstreamServer ) bool {
762
762
newServer .ID = serverNGX .ID
763
763
@@ -1036,7 +1036,7 @@ func (client *NginxClient) UpdateStreamServers(upstream string, servers []Stream
1036
1036
return nil , nil , nil , fmt .Errorf ("failed to update stream servers of %v upstream: %w" , upstream , err )
1037
1037
}
1038
1038
1039
- var formattedServers []StreamUpstreamServer
1039
+ formattedServers := make ( []StreamUpstreamServer , 0 , len ( servers ))
1040
1040
for _ , server := range servers {
1041
1041
server .Server = addPortToServer (server .Server )
1042
1042
formattedServers = append (formattedServers , server )
@@ -1083,7 +1083,7 @@ func (client *NginxClient) getIDOfStreamServer(upstream string, name string) (in
1083
1083
return - 1 , nil
1084
1084
}
1085
1085
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.
1087
1087
func haveSameParametersForStream (newServer StreamUpstreamServer , serverNGX StreamUpstreamServer ) bool {
1088
1088
newServer .ID = serverNGX .ID
1089
1089
if serverNGX .MaxConns != nil && newServer .MaxConns == nil {
@@ -1330,7 +1330,7 @@ func (client *NginxClient) GetNginxInfo() (*NginxInfo, error) {
1330
1330
return & info , nil
1331
1331
}
1332
1332
1333
- // GetCaches returns Cache stats
1333
+ // GetCaches returns Cache stats.
1334
1334
func (client * NginxClient ) GetCaches () (* Caches , error ) {
1335
1335
var caches Caches
1336
1336
err := client .get ("http/caches" , & caches )
0 commit comments