Documentation ¶
Overview ¶
Package middleware defines multiple gin middlewares
Index ¶
- Constants
- Variables
- func Context() gin.HandlerFunc
- func Cors() gin.HandlerFunc
- func GetLoggerConfig(formatter gin.LogFormatter, output io.Writer, skipPaths []string) gin.LoggerConfig
- func GetRequestIDFromContext(c *gin.Context) string
- func GetRequestIDFromHeaders(c *gin.Context) string
- func Limit(maxEventsPerSec float64, maxBurstSize int) gin.HandlerFunc
- func Logger() gin.HandlerFunc
- func LoggerWithConfig(conf gin.LoggerConfig) gin.HandlerFunc
- func NoCache(c *gin.Context)
- func Options(c *gin.Context)
- func Publish() gin.HandlerFunc
- func RequestID() gin.HandlerFunc
- func Secure(c *gin.Context)
- func Validation() gin.HandlerFunc
- type AuthOperator
- type AuthStrategy
Constants ¶
const ( RequestIDKey = "requestID" UsernameKey = "username" )
const ( RedisPubSubChannel = "iam.cluster.notifications" NoticePolicyChanged = "PolicyChanged" NoticeSecretChanged = "SecretChanged" )
Define Redis pub/sub events.
const (
// XRequestIDKey defines X-Request-ID key string.
XRequestIDKey = "X-Request-ID"
)
Variables ¶
var ErrorLimitExceeded = errors.New("Limit exceeded")
ErrorLimitExceeded defines Limit exceeded error.
var Middlewares = defaultMiddlewares()
Middlewares store registered middlewares.
Functions ¶
func Context ¶
func Context() gin.HandlerFunc
Context is a middleware that injects common prefix fields to gin.Context.
func GetLoggerConfig ¶
func GetLoggerConfig(formatter gin.LogFormatter, output io.Writer, skipPaths []string) gin.LoggerConfig
func GetRequestIDFromContext ¶
GetRequestIDFromContext returns 'RequestID' from the given context if present.
func GetRequestIDFromHeaders ¶
GetRequestIDFromHeaders returns 'RequestID' from the headers if present.
func Limit ¶
func Limit(maxEventsPerSec float64, maxBurstSize int) gin.HandlerFunc
Limit drops (HTTP status 429) the request if the limit is reached.
func Logger ¶
func Logger() gin.HandlerFunc
func LoggerWithConfig ¶
func LoggerWithConfig(conf gin.LoggerConfig) gin.HandlerFunc
func NoCache ¶
NoCache is a middleware function that appends headers to prevent the client from caching the HTTP response.
func Options ¶
Options is a middleware function that appends headers for options requests and aborts then exits the middleware chain and ends the request.
func Publish ¶
func Publish() gin.HandlerFunc
Publish publish a redis event to specified redis channel when some action occurred.
func RequestID ¶
func RequestID() gin.HandlerFunc
Add request id if no request id found in request headers.
func Validation ¶
func Validation() gin.HandlerFunc
Validation make sure users have the right resource permission and operation.
Types ¶
type AuthOperator ¶
type AuthOperator struct {
// contains filtered or unexported fields
}
AuthOperator is used to switch between different authentication strategy.
func (*AuthOperator) AuthFunc ¶
func (operator *AuthOperator) AuthFunc() gin.HandlerFunc
AuthFunc execute resource authentication.
func (*AuthOperator) SetStrategy ¶
func (operator *AuthOperator) SetStrategy(strategy AuthStrategy)
SetStrategy is used to set to another authentication strategy.
type AuthStrategy ¶
type AuthStrategy interface {
AuthFunc() gin.HandlerFunc
}
AuthStrategy defines the set of methods used to do resource authentication.