Packages to do common stuff.
Provide a default logfmt-style logger (using go-kit/log/levels) for your app.
logger := log.Default()
err := someAction()
logger.Error().Log(
"msg", "Something happened",
"during", "someAction",
"err", err
) // => level=error msg="Something happened", during=someAction err=<error as string>You can pre-set common fields:
l := logger.With("context", "README")
logger.Info("msg", "the message") // => level=info context=README msg="the message"Supported levels:
DebugInfoWarnErrorCrit
msg: human-readable version of the log, eg."fmt.Sprintf("error loading config: %v", err),"registering gorm callbacks".context: what the system was doing when the info was logged, egoauthprovider.endpoint,dbmigration.err: the error being loggedduring: the function that returned an error or induced the log, eginfluxdb.Client.Write
Use others that are relevant to your app or domain.
Provide a logger that doesn't do anything. This is quite useful for testing.
logger := log.NewNopLogger()export APPKIT_LOG_HUMAN=true Will make the logger outputs to a format that is easily to read for developers.
Helper for starting a HTTP server configured with a log.Logger. Provides Config and ListenAndServe.
-
ETag: will md5 your response body and include the hash in theETagHTTP header. If client provided the same ETag inIf-None-MatchHTTP header, will return304 Not Modifiedand discard the response.Does nothing (ie, passthrough) with non-
GETrequests and non-200 OKresponses. -
LogRequest: logs incoming HTTP requests withlog. Will log start and end of request. Uses logger from requestcontext.Context, so any fields set withlog.Logger.Withwill be included in the log. -
Recovery: recoverspanicin HTTP handlers, sends500 Internal Server Errorto the client, and re-panics the recovered error. -
DefaultMiddleware: Default middleware stack: request -> record HTTP status -> trace -> log -> recover. -
Compose: helper to chain middleware together.
Helper for opening a gorm.DB connection configured with a log.Logger. Provides Config and New.
A basic interface for monitoring request times and other arbitrary data, and recording data into InfluxDB.
Interface for pushing panics and arbitrary errors into error logging systems. Provides implementation for Airbrake monitoring.
This package is a wrapper of gorilla/sessions to fix the potential memory leaking problem.
Context wrappers and http.Handler middleware to setup and use various context.Contexts.
-
RequestTrace: generate unique id for each HTTP request. Useful for tracing everything that happens due to a single request. Used byLogger -
Logger: makes a given logger available viacontext.Context. Integrated withRequestTraceto add the request trace ID to anything logged via the context, if request is being traced. Used byserver.LogRequestmiddleware. -
HTTPStatus: records the HTTP status code for the request. Used byLogRequestto record the final response HTTP status code. -
Gorm: make agorm.DBavailable viacontext.Context.
For an "ABC" context:
ABCwill extract the "value" from acontext.Context. Generally returns the value and aboolto indicate whether the context actually had any value.WithABCishttp.Handlermiddleware that will enable "ABC" in a HTTP handler.ABCContextwill wrap acontext.Contextand provide a new context that can be passed toABC.MustGetABCis a wrapper aroundABCthat willpanicwhenABCwould return false. Useful when you need the context value and the only way you'd handle a missing value would be topanic.
Secret Box provides a simple interface for encryption of data for storage at rest.
It is implemented as a simple wrapper around golang.org/x/crypto/nacl/secretbox that takes care of handling the nonce.
Tracing supports distributed tracing of requests by linking together all of the parts of work that go into fulfilling a request.
For example, with a HTML front-end talking to back-end HTTPS APIs, it will link the original front-end request with any/all HTTP requests made to the back-end. Also, it can link together deeper requests made by the back-end to other APIs and services.
For now, It's implemented with OpenTracing and expects to talk to a Jaeger back-end.
Package to provide single interface for acquiring credentials for apps running on different platforms. Credentials that can be sourced:
- AWS
- InfluxDB
Places to source credentials from:
- Vault
- Local environment
Package to provide a common harness for running HTTP apps, that configures middleware that we use nearly all the time, and provides a standard way to configure the different parts of the service.