Documentation ¶
Index ¶
Constants ¶
const CtxLoggerKey = "request_id_logger"
CtxLoggerKey is the http.Request Context lookup key for the request ID logger
Variables ¶
var ( ErrForbidden = errors.New("access is forbidden") )
These are the errors that can be used in your controllers and matched against in the Errors middleware to perform special actions.
Functions ¶
func Log ¶
Log returns the Request ID scoped logger from the request Context and panics if it cannot be found. This function is only ever used by your controllers if your app uses the RequestID middlewares, otherwise you should use the controller's receiver logger directly.
func NewErrorManager ¶
NewErrorManager creates an error manager that can be used to create an error handler to wrap your controllers with
Types ¶
type AppHandler ¶
type AppHandler func(w http.ResponseWriter, r *http.Request) error
AppHandler is the function signature for controllers that return errors.
type ErrorContainer ¶
type ErrorContainer struct { // The error that will be returned by the controller Err error // The template file top render (e.g "errors/500") Template string // HTTP status code to respond with Code int // A custom handler to perform additional operations on this error Handler ErrorHandler }
ErrorContainer holds all of the relevant variables for a users custom error
func NewError ¶
func NewError(err error, code int, template string, handler ErrorHandler) ErrorContainer
NewError creates a new ErrorContainer that can be added to an errorManager. If you provide a handler here (instead of nil) then the Errors middleware will use your handler opposed to taking the default route of logging and rendering. You must handle logging and rendering yourself.
type ErrorHandler ¶
type ErrorHandler func(w http.ResponseWriter, r *http.Request, e ErrorContainer, render abcrender.Renderer) error
ErrorHandler is the function signature for user supplied error handlers.
type Middleware ¶
type Middleware struct { // Log is used for logging in your middleware and to // create a derived logger that includes the request ID. Log *zap.Logger }
Middleware exposes useful variables to every abcmiddleware handler
func (Middleware) Recover ¶
func (m Middleware) Recover(next http.Handler) http.Handler
Recover middleware recovers panics that occur and gracefully logs their error
func (Middleware) RequestIDLogger ¶
func (m Middleware) RequestIDLogger(next http.Handler) http.Handler
RequestIDLogger middleware creates a derived logger to include logging of the Request ID, and inserts it into the context object