Documentation
¶
Overview ¶
Package gohttpmw contains various middlewares that are helpful when building your http application
Index ¶
- Constants
- func AddToRequestLog(k string, f func(context.Context) interface{}) func(http.Handler) http.Handler
- func CSP(c string) func(http.Handler) http.Handler
- func GetAddToRequestLog(ctx context.Context) map[string]interface{}
- func GetRequestError(ctx context.Context) error
- func GetRequestID(ctx context.Context) string
- func Logger(l *logrus.Logger) func(http.Handler) http.Handler
- func LoggerZero(logger zerolog.Logger) func(http.Handler) http.Handler
- func RBAC(warden ladon.Warden, getRoleFunc func(context.Context) string) func(http.Handler) http.Handler
- func RequestID() func(http.Handler) http.Handler
- func Security() func(http.Handler) http.Handler
- func SetRequestError(r *http.Request, err error)
- type ContextKey
Constants ¶
const ( // ContextKeyAddToRequestLog allow storage of additional log fields in the context ContextKeyAddToRequestLog = ContextKey("AddToLog") )
const ContextKeyRequestError = ContextKey("requestError")
ContextKeyRequestError will allow the error to be passed down
const ( // ContextKeyRequestID allow storage of requestid in the context ContextKeyRequestID = ContextKey("requestID") )
Variables ¶
This section is empty.
Functions ¶
func AddToRequestLog ¶
func AddToRequestLog( k string, f func(context.Context) interface{}, ) func(http.Handler) http.Handler
AddToRequestLog allows to add more fields to the request log
func GetAddToRequestLog ¶
GetAddToRequestLog will retrieve the fileds to be added to the log
func GetRequestError ¶
GetRequestError will retrieve the request error from the context if there is one
func GetRequestID ¶
GetRequestID will retrieve the request id from the context if there is one
func Logger ¶
Logger will run the full request details if you need performance, look into loggerZero
func LoggerZero ¶
LoggerZero will log the full request details, with performance
func RBAC ¶
func RBAC( warden ladon.Warden, getRoleFunc func(context.Context) string, ) func(http.Handler) http.Handler
RBAC checks if the user is allowed to do the request
func RequestID ¶
RequestID adds a requestID to the request context ksuid is a unique global id that is orderable by time (a step up normal uuid)
func SetRequestError ¶
SetRequestError sets the error in the context so it can be picked up for logging
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey represents the key for context value
func (ContextKey) String ¶
func (c ContextKey) String() string