Categorygithub.com/inquizarus/nagg
modulepackage
1.2.0
Repository: https://github.com/inquizarus/nagg.git
Documentation: pkg.go.dev

# README

NAGG (Not Another Go Gateway)

This is an experimental API Gateway that probably shouldn't have been created. But here it is.

Usage

Either run the standalone binary or import and register NAGG in your own application.

Configuration

Environment variables

NameDescriptionDefault
NAGG_HTTP_PORTDefines which port to start built in server on8080
NAGG_LOG_LEVELDetermines which log level should be usedinfo
NAGG_HTTP_BASE_PATHDetermines which base path that NAGG will listen for requests on/
NAGG_CONFIG_JSONGateway configuration in JSON format (has precedence)-
NAGG_CONFIG_FILE_PATHGateway configuration in JSON format-

See examples/gateway.json for an example.

Expansion

When configuration is loaded from NAGG_CONFIG_JSON, standard Golang environment expansion will be applied to expand any variable statements in the string.

Given that there is an environment variable named FOO with the value bar then the following string in NAGG_CONFIG_JSON:

'{"foo":"$FOO"}'

Would result in the following string to be parsed as a config.

'{"foo":"bar"}'

Structure

Gateway

Global space for configuration in JSON structure and have two attributes that can be configured.

Middlewares, global middlewares to apply on each request and response. Routes, routes to handle requests for in the gateway.

Middleware

Middlewares has three attributes.

Name, which determines which middleware is loaded. Phase, either pre or post which determines if it's applied before upstream request is done or after. Pre are mainly for request handling while post are mainly for response handling. Args, List of args that are passed to the middleware factory function.

Default middlewares
NameDescriptionArgs
setHeaderSets header on request or responsekey,value
removeHeaderRemoves header from request or responsekey
moveHeaderMoves a headers value to another and removes original headersourceKey,destinationKey
setPathSets an absolute path for upstream requestpath
setPathPrefixAdds a prefix to the incoming requests pathprefix
setRequestParameterAdds a query parameter to the upstream requestkey,value
removeRequestParameterRemoves a query parameter from the upstream requestkey
dedupeResponseHeadersEnsures that specified header only has one value, value with index 0 will be usedkeys...
redirectRedirects requeststatusCode,destination

Route

Routes has four attributes.

Name, plainly an identifier for the route.

Predicates, object (described more in detail further down) that determines which requests will use this route.

Address, which upstream URL to use for requests. Can use the env:<environment variable key> to load ad-hoc from environment when route is triggered.

Middlewares, list of middlewares to apply to route.

Predicates

Currently predicates only support a static path.

# Packages

No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RegisterHTTPHandlers require a router that allows one route to handle all http methods.

# Interfaces

No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
MiddlewareLoader must return a middleware handler based on the given name with passed arguments correctly injected and type-casted for that specific middleware.
RoutesLoader retrieves routes from some location and tries to use the passed middleware loader for each route, if the passed middleware loader is nil or results in a nil middleware handler the default middleware loader will be used.