Documentation ¶
Overview ¶
Package middleware defines multiple gin middlewares.
Index ¶
Constants ¶
const UsernameKey = "username"
UsernameKey defines the key in gin context which represents the owner of the secret.
const XRequestIDKey = "X-Request-ID"
XRequestIDKey defines X-Request-ID key string.
Variables ¶
var Middlewares = map[string]gin.HandlerFunc{ "recovery": gin.Recovery(), "secure": Secure(), "options": Options(), "nocache": NoCache(), "cors": Cors(), "requestid": RequestID(), "context": Context(), "logger": Logger(), }
Middlewares store default middlewares.
Functions ¶
func Context ¶ added in v0.1.9
func Context() gin.HandlerFunc
Context returns a middleware that injects requestID and username to gin.Context.
func Logger ¶ added in v0.1.9
func Logger() gin.HandlerFunc
Logger returns a middleware that adds requestID and username to the loggin context.
func NoCache ¶
func NoCache() gin.HandlerFunc
NoCache returns a middleware that appends headers to prevent the client from caching the HTTP response.
func Options ¶
func Options() gin.HandlerFunc
Options returns a middleware that appends headers for OPTIONS requests.
func RequestID ¶
func RequestID() gin.HandlerFunc
RequestID returns a middleware that injects a 'X-Request-ID' into the context and request/response header of each request.
func Secure ¶
func Secure() gin.HandlerFunc
Secure returns a middleware that appends security and resource access headers.
Types ¶
type AuthOperator ¶
type AuthOperator struct {
// contains filtered or unexported fields
}
AuthOperator is used to switch between different auth strategy.
func (*AuthOperator) AuthFunc ¶
func (operator *AuthOperator) AuthFunc() gin.HandlerFunc
AuthFunc executes authentication.
func (*AuthOperator) SetStrategy ¶
func (operator *AuthOperator) SetStrategy(strategy AuthStrategy)
SetStrategy sets the strategy to operator.
type AuthStrategy ¶
type AuthStrategy interface {
AuthFunc() gin.HandlerFunc
}
AuthStrategy defines the behavior of a authenticator.