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:
Debug
Info
Warn
Error
Crit
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 theETag
HTTP header. If client provided the same ETag inIf-None-Match
HTTP header, will return304 Not Modified
and discard the response.Does nothing (ie, passthrough) with non-
GET
requests and non-200 OK
responses. -
LogRequest
: logs incoming HTTP requests withlog
. Will log start and end of request. Uses logger from requestcontext.Context
, so any fields set withlog.Logger.With
will be included in the log. -
Recovery
: recoverspanic
in HTTP handlers, sends500 Internal Server Error
to the client, and re-panic
s 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.Context
s.
-
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 withRequestTrace
to add the request trace ID to anything logged via the context, if request is being traced. Used byserver.LogRequest
middleware. -
HTTPStatus
: records the HTTP status code for the request. Used byLogRequest
to record the final response HTTP status code. -
Gorm
: make agorm.DB
available viacontext.Context
.
For an "ABC" context:
ABC
will extract the "value" from acontext.Context
. Generally returns the value and abool
to indicate whether the context actually had any value.WithABC
ishttp.Handler
middleware that will enable "ABC" in a HTTP handler.ABCContext
will wrap acontext.Context
and provide a new context that can be passed toABC
.MustGetABC
is a wrapper aroundABC
that willpanic
whenABC
would 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.