Documentation ¶
Index ¶
- Constants
- Variables
- func AccessLog() gin.HandlerFunc
- func Auth() gin.HandlerFunc
- func Breaker(opts ...BreakerOption) gin.HandlerFunc
- func Cors() gin.HandlerFunc
- func GetRequestIDFromContext(c *gin.Context) string
- func GetRequestIDFromHeaders(c *gin.Context) string
- func Logging() gin.HandlerFunc
- func Metrics(serviceName string, promOpts *PromOpts) gin.HandlerFunc
- func NoCache(c *gin.Context)
- func Options(c *gin.Context)
- func PromHandler(handler http.Handler) gin.HandlerFunc
- func Ratelimit(opts ...LimiterOption) gin.HandlerFunc
- func RequestID() gin.HandlerFunc
- func Secure(c *gin.Context)
- func SignMd5Middleware() gin.HandlerFunc
- func Timeout(t time.Duration) gin.HandlerFunc
- func Tracing(serviceName string, opts ...Option) gin.HandlerFunc
- type BreakerOption
- type LimiterOption
- type Option
- type PromOpts
- type RequestLabelMappingFn
Constants ¶
const ( // ContextRequestIDKey context request id for context ContextRequestIDKey = "request_id" // HeaderXRequestIDKey http header request ID key HeaderXRequestIDKey = "X-Request-ID" )
Variables ¶
var ErrLimitExceed = errors.New("[RATELIMIT] service unavailable due to rate limit exceeded")
ErrLimitExceed is service unavailable due to rate limit exceeded.
var ErrNotAllowed = errors.New("[BREAKER] request failed due to circuit breaker is open")
ErrNotAllowed is request failed due to circuit breaker triggered.
var Middlewares = defaultMiddlewares()
Middlewares global middleware
Functions ¶
func Breaker ¶
func Breaker(opts ...BreakerOption) gin.HandlerFunc
Breaker a circuit breaker middleware
func GetRequestIDFromContext ¶
GetRequestIDFromContext returns 'RequestID' from the given context if present.
func GetRequestIDFromHeaders ¶
GetRequestIDFromHeaders returns 'RequestID' from the headers if present.
func Logging ¶
func Logging() gin.HandlerFunc
Logging is a middleware function that logs the each request.
func Metrics ¶
func Metrics(serviceName string, promOpts *PromOpts) gin.HandlerFunc
Metrics returns a gin.HandlerFunc for exporting some Web metrics
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 PromHandler ¶
func PromHandler(handler http.Handler) gin.HandlerFunc
PromHandler wrappers the standard http.Handler to gin.HandlerFunc
func Ratelimit ¶
func Ratelimit(opts ...LimiterOption) gin.HandlerFunc
Ratelimit a circuit breaker middleware
func RequestID ¶
func RequestID() gin.HandlerFunc
RequestID is a middleware that injects a 'X-Request-ID' into the context and request/response header of each request.
Types ¶
type BreakerOption ¶
type BreakerOption func(*options)
BreakerOption is circuit breaker option.
func WithGroup ¶
func WithGroup(g *group.Group) BreakerOption
WithGroup with circuit breaker group. NOTE: implements generics circuitbreaker.CircuitBreaker
type LimiterOption ¶
type LimiterOption func(*limiterOptions)
LimiterOption is ratelimit option.
func WithLimiter ¶
func WithLimiter(limiter ratelimit.Limiter) LimiterOption
WithLimiter set Limiter implementation, default is bbr limiter
type Option ¶
type Option func(*config)
Option specifies instrumentation configuration options.
func WithPropagators ¶
func WithPropagators(propagators propagation.TextMapPropagator) Option
WithPropagators specifies propagators to use for extracting information from the HTTP requests. If none are specified, global ones will be used.
func WithTracerProvider ¶
func WithTracerProvider(provider oteltrace.TracerProvider) Option
WithTracerProvider specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.
type PromOpts ¶
type PromOpts struct { ExcludeRegexStatus string ExcludeRegexEndpoint string ExcludeRegexMethod string EndpointLabelMappingFn RequestLabelMappingFn }
PromOpts represents the Prometheus middleware Options. It is used for filtering labels by regex.
type RequestLabelMappingFn ¶
RequestLabelMappingFn .