Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUserNotFound = errors.New("user not found")
ErrUserNotFound should be returned from Get when the record is not found.
Functions ¶
func AuthCheckMiddleware ¶
AuthCheckMiddleware prevents someone from accessing a route that should be only allowed for users who are logged in. This middleware is designed to be used in client-side apps, because it does not handle redirecting.
It allows the user through if the UserManagement.IsAuthed returns true. Usually your implementation of this will check the users cookie.
UserManagement is an interface that implements context management to pass along the authed user state, whether that be a username or a simple bool to indicate that the requester is authed, or alternatively the implementation could just return nil, nil if there is no additional state to pass along. It also implements a function to check whether the supplied request holds details of an authed user. Usually this means your implementation would involve checking the request variable for an active and valid cookie.
log is a zerolog logger that is used if a logger cannot be found in the request context. If you're using request ID's, the request ID middlewares will handle this for you.
func BasicPanicRecoverHandler ¶
func BasicPanicRecoverHandler(w http.ResponseWriter, r *http.Request)
BasicPanicRecoverHandler is a basic panic recovery handler that will add the X-Request-ID header if present in the context, and return a http.StatusInternalServerError.
This can be used as the errorHandler argument for ZerologRecover.
func ValidationConverter ¶
Types ¶
type MW ¶
MW is an interface defining middleware wrapping
func ZerologRecover ¶
func ZerologRecover(fallback *zerolog.Logger, errorHandler http.HandlerFunc) MW
ZerologRecover will attempt to log a panic, as well as produce a reasonable error for the client by calling the passed in errorHandler function. If your app is using request-id logging, don't forget to write the request-id header in your errorHandler function as X-Request-ID. Or use the BasicPanicRecoverHandler if you want to have that done for you, and simply want to return a StatusInternalServerError on panics.
It uses the zerolog logger and attempts to look up a request-scoped logger created with this package before using the passed in logger.
The zerolog logger that's used here needs to have stacktrace logging enabled by setting zerolog.ErrorStackMarshaler, if using this middleware.
func ZerologRequestIDLogger ¶
ZerologRequestIDLogger returns a request id logger middleware. This only works if chi has inserted a request id into the stack first.
type UnexpectedErrorHandler ¶
type UnexpectedErrorHandler struct {
// contains filtered or unexported fields
}
func NewUnexpectedErrorHandler ¶
func NewUnexpectedErrorHandler(log *zerolog.Logger) UnexpectedErrorHandler
NewUnexpectedErrorHandler is a validation error handler and http 500 error handler, primarily for use with oa3 generated APIs.
oa3 API's take a validation error converter and a error handler on initialization. The returned object here can be used as the error handler argument, and the ValidationConverter function in this package can be used the validation converter argument.
func (UnexpectedErrorHandler) Wrap ¶
func (e UnexpectedErrorHandler) Wrap(fn func(w http.ResponseWriter, r *http.Request) error) http.Handler