package
1.3.6
Repository: https://github.com/nytimes/gizmo.git
Documentation: pkg.go.dev

# Packages

Package kit implements an opinionated server based on go-kit primitives.

# Functions

AddIPToContext will attempt to pull an IP address out of the request and set it into a gorilla context.
ContextFields will take a request and convert a context map to logrus Fields.
ContextToHTTP is a middleware func to convert a ContextHandler an http.Handler.
ContextWithForwardForIP returns new context with forward for ip.
ContextWithUserIP returns new context with user ip address.
CORSHandler is a middleware func for setting all headers that enable CORS.
GetForwardedIP returns the "X-Forwarded-For" header value.
GetInt64Var is a helper to pull gorilla mux Vars.
GetIP returns the IP address for the given request.
GetUInt64Var is a helper to pull gorilla mux Vars.
Init will set up our name, logging, healthchecks and parse flags.
JSONContextToHTTP is a middleware func to convert a ContextHandler an http.Handler.
JSONPHandler is a middleware func for wrapping response body with JSONP.
JSONToHTTP is the middleware func to convert a JSONEndpoint to an http.HandlerFunc.
LoadConfigFromEnv will attempt to load a Server object from environment variables.
LogWithFields will feed any request context into a logrus Entry.
MetricsNamespace returns "apps.{hostname prefix}", which is the convention used in NYT ESX environment.
NewAccessLogMiddleware will wrap a logrotate-aware Apache-style access log handler around the given http.Handler if an access log location is provided by the config, or optionally send access logs to stdout.
NewActivityMonitor will return a new ActivityMonitor instance.
NewCustomHealthCheck will return a new CustomHealthCheck with the given path and handler.
NewHealthCheckHandler will inspect the config to generate the appropriate HealthCheckHandler.
NewRouter will return the router specified by the server config.
NewServer will inspect the config and generate the appropriate Server implementation.
NewSimpleHealthCheck will return a new SimpleHealthCheck instance.
NewSimpleServer will init the mux, exit channel and build the address from the given port.
NoCacheHandler is a middleware func for setting the Cache-Control to no-cache.
ParseTruthyFalsy is a helper method to attempt to parse booleans in APIs that have no set contract on what a boolean should look like.
Register will add a new Service to the DefaultServer.
RegisterHealthHandler will create a new HealthCheckHandler from the given config and add a handler to the given router.
RegisterProfiler will add handlers for pprof endpoints if the config has them enabled.
Run will start the DefaultServer and set it up to Stop() on a kill signal.
SetConfigOverrides will check the *CLI variables for any values and override the values in the given config if they are set.
SetLogLevel will set the appropriate logrus log level given the server config.
SetRouteVars will set the given value into into the request context with the shared 'vars' storage key.
Stop will stop the default server.
Vars is a helper function for accessing route parameters from any server.Router implementation.
WithCloseHandler returns a Handler cancelling the context when the client connection close unexpectedly.

# Constants

JSONContentType can be used for setting the Content-Type header for JSON encoding.
UserForwardForIPKey is key to set/retrieve value from context.
UserIPKey is key to set/retrieve value from context.

# Variables

ErrMultiRegister occurs when a Register method is called multiple times.
Log is the global logger for the server.
Name is used for status and logging.
UnexpectedServerError is returned with a 500 status code when SimpleServer recovers from a panic in a request.
Version is meant to be set with the current package version at build time.

# Structs

ActivityMonitor can be used to count and share the number of active requests.
Config holds info required to configure a gizmo server.Server.
CustomHealthCheck is a HealthCheckHandler that uses a custom http.Handler provided to the server via `config.CustomHealthCheckHandler`.
GorillaRouter is a Router implementation for the Gorilla web toolkit's `mux.Router`.
SimpleHealthCheck is a basic HealthCheckHandler implementation that _always_ returns with an "ok" status and shuts down immediately.
SimpleServer is a basic http Server implementation for serving SimpleService, JSONService or MixedService implementations.
TCPKeepAliveListener sets TCP keep-alive timeouts on accepted connections.

# Interfaces

ContextHandler is an equivalent to http.Handler but with additional param.
ContextService is an interface defining a service that is made up of ContextHandlerFuncs.
HealthCheckHandler is an interface used by SimpleServer and RPCServer to allow users to customize their service's health check.
JSONService is an interface defining a service that is made up of JSONEndpoints.
MixedContextService is an interface defining a service that is made up of JSONContextEndpoints and ContextHandlerFuncs.
MixedService is an interface defining service that offer JSONEndpoints and simple http.HandlerFunc endpoints.
Router is an interface to wrap different router types to be embedded within Gizmo server.Server implementations.
RPCService is an interface defining an grpc-compatible service that also offers JSONContextEndpoints and ContextHandlerFuncs.
Server is the basic interface that defines what to expect from any server.
Service is the most basic interface of a service that can be received and hosted by a Server.
SimpleService is an interface defining a service that is made up of http.HandlerFuncs.

# Type aliases

ContextHandlerFunc is an equivalent to SimpleService's http.HandlerFunc.
ContextKey used to create context keys.
JSONContextEndpoint is the JSONContextService equivalent to JSONService's JSONEndpoint.
JSONEndpoint is the JSONService equivalent to SimpleService's http.HandlerFunc.