Categorygithub.com/qba73/ngx
modulepackage
0.0.0-20230417203742-dec383d02bed
Repository: https://github.com/qba73/ngx.git
Documentation: pkg.go.dev

# README

Go Go Report Card GitHub go.mod Go version License

ngx

ngx is a Go client library for NGINX Plus API. The project was initially based on the fork of the open source NGINX Plus client API.

The library works against versions 4 to 8 of the NGINX Plus API. The table below shows the version of NGINX Plus where the API was first introduced.

Click to see API and NGINX Plus version table
API versionNGINX Plus version
4R18
5R19
6R20
7R25
8R27

Using the Go library

Import the library using:

import "github.com/qba73/ngx"

Creating a client

Create a new Client object by calling ngx.NewClient(baseURL)

client, err := ngx.NewClient("http://localhost:8080/api")
if err != nil {
    // handle error
}

Or create a client with customized http Client:

customHTTPClient := &http.Client{}

client, err := ngx.NewClient(
    "http://localhost:8080/api",
    ngx.WithHTTPClient(customHTTPClient),
)
if err != nil {
    // handle error
}

Or create a client to work with specific version of NGINX instance:

client, err := ngx.NewClient(
    "http://localhost:8080/api",
    ngx.WithVersion(7),
)
if err != nil {
    // handle error
}

Testing

Run tests

make dox
Click to see test run results
$ gotestdox
 ✔ Check server updates is valid on valid input (0.00s)
 ✔ Check stream server updates is valid on valid input (0.00s)
 ✔ Upstream servers config is valid on valid input (0.00s)
 ✔ Upstream stream servers configuration is valid on valid input (0.00s)
 ✔ Server address is valid on valid input with host and port (0.00s)
 ✔ Server address is valid on valid input with IPV6 address and without port (0.00s)
 ✔ Server address is valid on valid input with IPV4 address and without port (0.00s)
 ✔ Server address is valid on valid input with address and without port (0.00s)
 ✔ Server address is valid on valid input with unix socket (0.00s)
 ✔ Server address is valid on valid input with IPV6 and port (0.00s)
 ✔ Server address is valid on valid input with IPV4 and port (0.00s)
 ✔ NGINX server status is valid on valid input request params (0.00s)
 ✔ Request get NGINXURL is valid on valid fields (0.00s)
 ✔ Get NGINX status errors on invalid request param (0.00s)
 ✔ Client uses valid request path on valid request params (0.00s)
 ✔ Client retrives info about running NGINX instance (0.00s)
 ✔ Client retrives NGINX status on valid parameters (0.00s)

Contributing

If you have any suggestions or experience issues with the NGINX Plus Go Client, please create an issue or send a pull request on GitHub.

# Functions

NewClient takes NGINX base URL and constructs a new default client.
WithHTTPClient is a func option that configures NGINX Client to use a custom HTTP Client.
WithVersion is a func option that configures version of the NGINX API the Client talks to.

# Structs

CacheStats are basic cache stats.
NginxClient lets you access NGINX Plus API.
Connections represents connection related stats.
ExtendedCacheStats are extended cache stats.
HealthChecks represents health check related stats for a peer.
HTTPCache represents a zone's HTTP Cache.
HTTPCodes represents HTTP response codes.
HTTPLimitRequest represents HTTP Requests Rate Limiting.
HTTPRequests represents HTTP request related stats.
LimitConnection represents Connections Limiting.
LocationZone represents location_zones related stats.
NginxInfo contains general information about NGINX Plus.
Pages represents the slab memory usage stats.
Peer represents peer (upstream server) related stats.
Processes represents processes related stats.
Queue represents queue related stats for an upstream.
Resolver represents resolvers related stats.
ResolverRequests represents resolver requests.
ResolverResponses represents resolver responses.
Responses represents HTTP response related stats.
ServerZone represents server zone related stats.
Sessions represents stream session related stats.
Slab represents slab related stats.
Slot represents slot related stats.
SSL represents SSL related stats.
Stats represents NGINX Plus stats fetched from the NGINX Plus API.
StreamPeer represents peer (stream upstream server) related stats.
StreamServerZone represents stream server zone related stats.
StreamUpstream represents stream upstream related stats.
StreamUpstreamServer lets you configure Stream upstreams.
StreamZoneSync represents the sync information per each shared memory zone and the sync information per node in a cluster.
StreamZoneSyncStatus represents the status of a shared memory zone.
SyncZone represents the synchronization status of a shared memory zone.
Upstream represents upstream related stats.
UpstreamServer lets you configure HTTP upstreams.

# Type aliases

Caches is a map of cache stats by cache zone.
HTTPLimitConnections represents limit connections related stats.
HTTPLimitRequests represents limit requests related stats.
KeyValPairs are the key-value pairs stored in a zone.
KeyValPairsByZone are the KeyValPairs for all zones, by zone name.
LocationZones represents location_zones related stats.
Resolvers represents resolvers related stats.
ServerZones is map of server zone stats by zone name.
Slabs is map of slab stats by zone name.
Slots is a map of slots by slot size.
StreamLimitConnections represents limit connections related stats.
StreamServerZones is map of stream server zone stats by zone name.
StreamUpstreams is a map of stream upstream stats by upstream name.
Upstreams is a map of upstream stats by upstream name.