Documentation ¶
Index ¶
- Variables
- func CacheMiddleware(ttl time.Duration) func(http.Handler) http.Handler
- func ContentType(contentType string) func(http.Handler) http.Handler
- func CtxMiddleWare(extenders ...func(context.Context) context.Context) func(http.Handler) http.Handler
- func DefaultMiddlewares(r chi.Router, args ...interface{})
- func GetRequestID(ctx context.Context) string
- func Log(r *http.Request) *logan.Entry
- func LoganMiddleware(entry *logan.Entry, args ...interface{}) func(http.Handler) http.Handler
- func RecoverMiddleware(args ...interface{}) func(http.Handler) http.Handler
- func Render(w http.ResponseWriter, res interface{})
- func RenderErr(w http.ResponseWriter, errs ...*jsonapi.ErrorObject)
- func Serve(ctx context.Context, handler http.Handler, cfg ServeConfig, opts ServeOpts)
- func SetContextLog(ctx context.Context, log *logan.Entry) context.Context
- type Logger
- type LoggerGetter
- type LoggerSetter
- type RequestIDProvider
- type ServeConfig
- type ServeOpts
Constants ¶
This section is empty.
Variables ¶
var CtxMiddleware = CtxMiddleWare
Functions ¶
func CacheMiddleware ¶
CacheMiddleware returns middleware with directive for a browser to cache the response for some TTL (time to live).
func CtxMiddleWare ¶
func CtxMiddleWare(extenders ...func(context.Context) context.Context) func(http.Handler) http.Handler
DEPRECATED: use typo-free CtxMiddleware instead
func DefaultMiddlewares ¶
DefaultMiddlewares provide sane defaults that should just work
func GetRequestID ¶
func LoganMiddleware ¶
LoganMiddleware by default will just log the begging and end of the request Also it might take use of number of optionally injected arguments like: - time.Duration will set threshold for logging a warning of slow request - LoggerSetter - will be called with *logan.Entry which will contain auxiliary fields to identify the request - RequestIDProvider - will set result into fields of *logan.Entry if LoggerSetter is provided
func RecoverMiddleware ¶
RecoverMiddleware by default will just catch handler panic. Also it might take use of number of optionally injected arguments like: - LoggerGetter request context log getter - Logger implementation to log stacktrace with Error level - *jsonapi.ErrorObject to render error body - *raven.Client to report exception to Sentry
func Render ¶
func Render(w http.ResponseWriter, res interface{})
func RenderErr ¶
func RenderErr(w http.ResponseWriter, errs ...*jsonapi.ErrorObject)
Types ¶
type Logger ¶
type Logger interface {
Log(level uint32, fields map[string]interface{}, err error, withStack bool, args ...interface{})
}
Logger abstract logger interface providing all possible bells and whistles, mainly for decoupling `distributed_lab/logan` package
type LoggerGetter ¶
LoggerGetter get *logan.Entry from request context
type LoggerSetter ¶
LoggerSetter - sets specified entry into ctx
type RequestIDProvider ¶
RequestIDProvider - returns ID of the request from ctx if one present
type ServeConfig ¶
ServeConfig - defines external dependencies of serve
type ServeOpts ¶
type ServeOpts struct { // ReadTimeout is the maximum duration for reading the entire // request, including the body. Default is 5s. ReadTimeout time.Duration // WriteTimeout, unless connection is HTTPS (in our case never as we are always behind nginx), // covers the time from the end of the request header read to the end of the response write // (a.k.a. the lifetime of the ServeHTTP). Default 10s WriteTimeout time.Duration // ShutdownTimeout is maximum duration for waiting for server to shutdown. Default 15s. ShutdownTimeout time.Duration }
ServeOpts - defines serve configuration options that must be specified by developer