Documentation
¶
Index ¶
- Constants
- Variables
- func AddTrailingSlash() zinc.Middleware
- func AllowContentEncoding(encodings ...string) zinc.Middleware
- func AllowContentType(types ...string) zinc.Middleware
- func BasicAuth(validator BasicAuthValidator) zinc.Middleware
- func BasicAuthUsername(c *zinc.Context) (string, bool)
- func BasicAuthWithConfig(config BasicAuthConfig) zinc.Middleware
- func BodyDump(observer BodyDumpObserver) zinc.Middleware
- func BodyDumpWithConfig(config BodyDumpConfig) zinc.Middleware
- func BodyLimit(limit int64) zinc.Middleware
- func BodyLimitWithConfig(config BodyLimitConfig) zinc.Middleware
- func CORS(allowOrigins ...string) zinc.Middleware
- func CORSWithConfig(config CORSConfig) zinc.Middleware
- func CORSWithOptions(options ...CORSOption) zinc.Middleware
- func CSRF() zinc.Middleware
- func CSRFToken(c *zinc.Context) (string, bool)
- func CSRFWithConfig(config CSRFConfig) zinc.Middleware
- func CasbinAuth(enforcer CasbinEnforcer, subject CasbinValueFunc) zinc.Middleware
- func CasbinAuthWithConfig(config CasbinAuthConfig) zinc.Middleware
- func ContextTimeout(timeout time.Duration) zinc.Middleware
- func ContextTimeoutRemaining(c *zinc.Context) (time.Duration, bool)
- func ContextTimeoutWithConfig(config ContextTimeoutConfig) zinc.Middleware
- func Decompress() zinc.Middleware
- func DecompressWithConfig(config DecompressConfig) zinc.Middleware
- func DefaultRateLimiter() zinc.Middleware
- func Gzip() zinc.Middleware
- func GzipWithConfig(config GzipConfig) zinc.Middleware
- func Heartbeat(path string) zinc.Middleware
- func IPRateLimiter(rate, capacity float64) zinc.Middleware
- func JWT(keyFunc JWTKeyFunc) zinc.Middleware
- func JWTClaims[T any](c *zinc.Context) (T, bool)
- func JWTToken(c *zinc.Context) (*jwtgo.Token, bool)
- func JWTTokenString(c *zinc.Context) (string, bool)
- func JWTWithConfig(config JWTConfig) zinc.Middleware
- func Jaeger(observer JaegerObserver) zinc.Middleware
- func JaegerWithConfig(config JaegerConfig) zinc.Middleware
- func KeyAuth(validator KeyAuthValidator) zinc.Middleware
- func KeyAuthWithConfig(config KeyAuthConfig) zinc.Middleware
- func Logger() zinc.Middleware
- func LoggerWithConfig(config RequestLoggerConfig) zinc.Middleware
- func Maybe(predicate func(*zinc.Context) bool, mw zinc.Middleware) zinc.Middleware
- func MethodOverride() zinc.Middleware
- func MethodOverrideWithConfig(config MethodOverrideConfig) zinc.Middleware
- func MustBasicAuthUsername(c *zinc.Context) string
- func MustCSRFToken(c *zinc.Context) string
- func MustJWTClaims[T any](c *zinc.Context) T
- func MustJWTToken(c *zinc.Context) *jwtgo.Token
- func MustJWTTokenString(c *zinc.Context) string
- func NoCache() zinc.Middleware
- func Pprof() zinc.Middleware
- func PprofWithPrefix(prefix string) zinc.Middleware
- func Prometheus(metrics ...*PrometheusMetrics) zinc.Middleware
- func PrometheusHandler(metrics ...*PrometheusMetrics) zinc.HandlerFunc
- func PrometheusWithConfig(config PrometheusConfig) zinc.Middleware
- func Proxy(target string) zinc.Middleware
- func ProxyWithConfig(config ProxyConfig) zinc.Middleware
- func RandomRequestID(*zinc.Context) (string, error)
- func RateLimiter(config ...RateLimiterConfig) zinc.Middleware
- func RealIP() zinc.Middleware
- func Recover() zinc.Middleware
- func RecoverWithConfig(config RecoverConfig) zinc.Middleware
- func Redirect(from, to string, statusCode ...int) zinc.Middleware
- func RedirectWithConfig(config RedirectConfig) zinc.Middleware
- func RedirectWithRules(rules map[string]string, statusCode ...int) zinc.Middleware
- func RemoveTrailingSlash() zinc.Middleware
- func RequestID() zinc.Middleware
- func RequestIDValue(c *zinc.Context) string
- func RequestIDWithConfig(config RequestIDConfig) zinc.Middleware
- func RequestLogger() zinc.Middleware
- func RequestLoggerWithConfig(config RequestLoggerConfig) zinc.Middleware
- func Rewrite(from, to string) zinc.Middleware
- func RewriteWithConfig(config RewriteConfig) zinc.Middleware
- func RewriteWithRules(rules map[string]string) zinc.Middleware
- func RouteHeaders(rules ...HeaderRoute) zinc.Middleware
- func Secure() zinc.Middleware
- func SecureWithConfig(config SecureConfig) zinc.Middleware
- func SessionCookie(name, secret string) zinc.Middleware
- func SessionWithConfig(config SessionConfig) zinc.Middleware
- func SetHeader(key, value string) zinc.Middleware
- func Static(root string) zinc.Middleware
- func StaticFS(filesystem fs.FS) zinc.Middleware
- func StaticFrom(prefix, root string) zinc.Middleware
- func StaticWithConfig(config StaticConfig) zinc.Middleware
- func Throttle(limit int) zinc.Middleware
- func TrailingSlash() zinc.Middleware
- func TrailingSlashWithConfig(config TrailingSlashConfig) zinc.Middleware
- type BasicAuthConfig
- type BasicAuthCredentials
- type BasicAuthErrorHandler
- type BasicAuthExtractor
- type BasicAuthIdentity
- type BasicAuthPair
- type BasicAuthSource
- type BasicAuthValidator
- type BodyDumpConfig
- type BodyDumpObserver
- type BodyDumpRedactor
- type BodyDumpSnapshot
- type BodyLimitConfig
- type BodyLimitError
- type BodyLimitSource
- type CORSConfig
- type CORSOption
- func CORSAllowCredentials(allow bool) CORSOption
- func CORSAllowHeaders(headers ...string) CORSOption
- func CORSAllowMethods(methods ...string) CORSOption
- func CORSAllowOrigins(origins ...string) CORSOption
- func CORSExposeHeaders(headers ...string) CORSOption
- func CORSMaxAge(maxAge time.Duration) CORSOption
- func CORSMaxAgeSeconds(seconds int) CORSOption
- func CORSSkipper(skipper func(*zinc.Context) bool) CORSOption
- type CSRFConfig
- type CSRFCookie
- type CSRFDecision
- type CSRFErrorHandler
- type CSRFFetchSite
- type CSRFFetchSiteDecider
- type CSRFGenerator
- type CSRFReader
- type CSRFReason
- type CSRFState
- type CSRFViolation
- type CasbinAuthConfig
- type CasbinEnforcer
- type CasbinErrorHandler
- type CasbinValueFunc
- type ContextTimeoutConfig
- type ContextTimeoutError
- type ContextTimeoutErrorHandler
- type ContextTimeoutInfo
- type DecompressConfig
- type GzipConfig
- type HeaderRoute
- type JWTConfig
- type JWTErrorHandler
- type JWTExtractor
- func JWTFromAuthHeader(scheme string) JWTExtractor
- func JWTFromCookie(name string) JWTExtractor
- func JWTFromFirst(extractors ...JWTExtractor) JWTExtractor
- func JWTFromHeader(header string) JWTExtractor
- func JWTFromHeaderPrefix(header, prefix string) JWTExtractor
- func JWTFromQuery(name string) JWTExtractor
- type JWTKeyFunc
- type JWTParseTokenFunc
- type JWTValidateFunc
- type JaegerConfig
- type JaegerObserver
- type JaegerOperationName
- type JaegerSpan
- type KeyAuthConfig
- type KeyAuthCredentials
- type KeyAuthErrorHandler
- type KeyAuthExtractor
- func KeyAuthFromAuthorizationHeader() KeyAuthExtractor
- func KeyAuthFromCookie(name string) KeyAuthExtractor
- func KeyAuthFromFirst(extractors ...KeyAuthExtractor) KeyAuthExtractor
- func KeyAuthFromHeader(header string) KeyAuthExtractor
- func KeyAuthFromHeaderPrefix(header, prefix string) KeyAuthExtractor
- func KeyAuthFromQuery(name string) KeyAuthExtractor
- type KeyAuthSource
- type KeyAuthState
- type KeyAuthValidator
- type MethodOverrideConfig
- type MethodOverrideGetter
- type PrometheusConfig
- type PrometheusMetrics
- type ProxyBalancer
- type ProxyConfig
- type ProxyTarget
- type RateLimiterConfig
- type RecoverConfig
- type RecoverError
- type RecoverHandler
- type RedirectConfig
- type RequestIDConfig
- type RequestIDGenerator
- type RequestIDState
- type RequestLoggerConfig
- type RequestLoggerValues
- type RewriteConfig
- type SecureConfig
- type Session
- type SessionConfig
- type StaticConfig
- type TokenBucket
- type TrailingSlashConfig
Constants ¶
const ( BodyDumpDefaultMaxRequestBytes int64 = 1 << 20 BodyDumpDefaultMaxResponseBytes int64 = 1 << 20 )
const ( B int64 = 1 KB = 1024 * B MB = 1024 * KB GB = 1024 * MB )
const ( HeaderXHTTPMethodOverride = "X-HTTP-Method-Override" HeaderXOriginalMethod = "X-Original-Method" )
const HeaderUberTraceID = "Uber-Trace-Id"
Variables ¶
var ( ErrBasicAuthCredentialsMissing = errors.New("zincbasicauth: credentials missing") ErrBasicAuthCredentialsMalformed = errors.New("zincbasicauth: credentials malformed") ErrBasicAuthCredentialsInvalid = errors.New("zincbasicauth: credentials invalid") )
var ( ErrCSRFTokenMissing = errors.New("zinccsrf: request token missing") ErrCSRFCookieMissing = errors.New("zinccsrf: csrf cookie missing") ErrCSRFTokenInvalid = errors.New("zinccsrf: request token invalid") ErrCSRFFetchSiteRejected = errors.New("zinccsrf: request rejected by fetch metadata") )
var ( ErrDecompressUnsupportedEncoding = errors.New("zincdecompress: unsupported content encoding") ErrDecompressInvalidBody = errors.New("zincdecompress: invalid compressed body") )
var ( ErrJWTTokenMissing = errors.New("zincjwt: token missing") ErrJWTTokenMalformed = errors.New("zincjwt: token malformed") ErrJWTTokenInvalid = errors.New("zincjwt: token invalid") )
var ( ErrKeyAuthKeyMissing = errors.New("zinckeyauth: key missing") ErrKeyAuthKeyInvalid = errors.New("zinckeyauth: key invalid") )
var ErrBodyLimitExceeded = errors.New("zincbodylimit: request body exceeded configured limit")
var ErrCasbinAuthRejected = errors.New("zinccasbin: request rejected")
var ErrContextTimeout = errors.New("zinccontexttimeout: request context deadline exceeded")
var ErrSessionInvalid = errors.New("zincsession: invalid session")
Functions ¶
func AddTrailingSlash ¶ added in v0.1.1
func AddTrailingSlash() zinc.Middleware
func AllowContentEncoding ¶ added in v0.1.2
func AllowContentEncoding(encodings ...string) zinc.Middleware
func AllowContentType ¶ added in v0.1.2
func AllowContentType(types ...string) zinc.Middleware
func BasicAuth ¶ added in v0.0.80
func BasicAuth(validator BasicAuthValidator) zinc.Middleware
func BasicAuthWithConfig ¶ added in v0.0.80
func BasicAuthWithConfig(config BasicAuthConfig) zinc.Middleware
func BodyDump ¶ added in v0.0.80
func BodyDump(observer BodyDumpObserver) zinc.Middleware
func BodyDumpWithConfig ¶ added in v0.0.80
func BodyDumpWithConfig(config BodyDumpConfig) zinc.Middleware
func BodyLimit ¶ added in v0.0.80
func BodyLimit(limit int64) zinc.Middleware
func BodyLimitWithConfig ¶ added in v0.0.80
func BodyLimitWithConfig(config BodyLimitConfig) zinc.Middleware
func CORS ¶ added in v0.0.80
func CORS(allowOrigins ...string) zinc.Middleware
func CORSWithConfig ¶ added in v0.0.80
func CORSWithConfig(config CORSConfig) zinc.Middleware
func CORSWithOptions ¶ added in v0.0.80
func CORSWithOptions(options ...CORSOption) zinc.Middleware
func CSRF ¶ added in v0.0.80
func CSRF() zinc.Middleware
func CSRFWithConfig ¶ added in v0.0.80
func CSRFWithConfig(config CSRFConfig) zinc.Middleware
func CasbinAuth ¶ added in v0.1.1
func CasbinAuth(enforcer CasbinEnforcer, subject CasbinValueFunc) zinc.Middleware
func CasbinAuthWithConfig ¶ added in v0.1.1
func CasbinAuthWithConfig(config CasbinAuthConfig) zinc.Middleware
func ContextTimeout ¶ added in v0.0.80
func ContextTimeout(timeout time.Duration) zinc.Middleware
func ContextTimeoutRemaining ¶ added in v0.0.80
func ContextTimeoutWithConfig ¶ added in v0.0.80
func ContextTimeoutWithConfig(config ContextTimeoutConfig) zinc.Middleware
func Decompress ¶ added in v0.1.1
func Decompress() zinc.Middleware
func DecompressWithConfig ¶ added in v0.1.1
func DecompressWithConfig(config DecompressConfig) zinc.Middleware
func DefaultRateLimiter ¶
func DefaultRateLimiter() zinc.Middleware
DefaultRateLimiter returns a rate limiter with default settings
func Gzip ¶ added in v0.1.1
func Gzip() zinc.Middleware
func GzipWithConfig ¶ added in v0.1.1
func GzipWithConfig(config GzipConfig) zinc.Middleware
func Heartbeat ¶ added in v0.1.2
func Heartbeat(path string) zinc.Middleware
func IPRateLimiter ¶
func IPRateLimiter(rate, capacity float64) zinc.Middleware
IPRateLimiter returns a rate limiter that limits by IP address
func JWT ¶ added in v0.0.80
func JWT(keyFunc JWTKeyFunc) zinc.Middleware
func JWTWithConfig ¶ added in v0.0.80
func JWTWithConfig(config JWTConfig) zinc.Middleware
func Jaeger ¶ added in v0.1.1
func Jaeger(observer JaegerObserver) zinc.Middleware
func JaegerWithConfig ¶ added in v0.1.1
func JaegerWithConfig(config JaegerConfig) zinc.Middleware
func KeyAuth ¶ added in v0.1.1
func KeyAuth(validator KeyAuthValidator) zinc.Middleware
func KeyAuthWithConfig ¶ added in v0.1.1
func KeyAuthWithConfig(config KeyAuthConfig) zinc.Middleware
func LoggerWithConfig ¶ added in v0.0.73
func LoggerWithConfig(config RequestLoggerConfig) zinc.Middleware
LoggerWithConfig is an alias for RequestLoggerWithConfig.
func Maybe ¶ added in v0.1.2
func Maybe(predicate func(*zinc.Context) bool, mw zinc.Middleware) zinc.Middleware
func MethodOverride ¶ added in v0.1.1
func MethodOverride() zinc.Middleware
func MethodOverrideWithConfig ¶ added in v0.1.1
func MethodOverrideWithConfig(config MethodOverrideConfig) zinc.Middleware
func MustBasicAuthUsername ¶ added in v0.0.80
func MustCSRFToken ¶ added in v0.0.80
func MustJWTClaims ¶ added in v0.0.80
func MustJWTTokenString ¶ added in v0.0.80
func NoCache ¶ added in v0.1.2
func NoCache() zinc.Middleware
func Pprof ¶ added in v0.1.2
func Pprof() zinc.Middleware
func PprofWithPrefix ¶ added in v0.1.2
func PprofWithPrefix(prefix string) zinc.Middleware
func Prometheus ¶ added in v0.1.1
func Prometheus(metrics ...*PrometheusMetrics) zinc.Middleware
func PrometheusHandler ¶ added in v0.1.1
func PrometheusHandler(metrics ...*PrometheusMetrics) zinc.HandlerFunc
func PrometheusWithConfig ¶ added in v0.1.1
func PrometheusWithConfig(config PrometheusConfig) zinc.Middleware
func Proxy ¶ added in v0.1.1
func Proxy(target string) zinc.Middleware
func ProxyWithConfig ¶ added in v0.1.1
func ProxyWithConfig(config ProxyConfig) zinc.Middleware
func RateLimiter ¶
func RateLimiter(config ...RateLimiterConfig) zinc.Middleware
RateLimiter returns a rate limiter middleware
func RealIP ¶ added in v0.1.2
func RealIP() zinc.Middleware
func Recover ¶ added in v0.1.1
func Recover() zinc.Middleware
func RecoverWithConfig ¶ added in v0.1.1
func RecoverWithConfig(config RecoverConfig) zinc.Middleware
func RedirectWithConfig ¶ added in v0.1.1
func RedirectWithConfig(config RedirectConfig) zinc.Middleware
func RedirectWithRules ¶ added in v0.1.1
func RedirectWithRules(rules map[string]string, statusCode ...int) zinc.Middleware
func RemoveTrailingSlash ¶ added in v0.1.1
func RemoveTrailingSlash() zinc.Middleware
func RequestID ¶ added in v0.1.1
func RequestID() zinc.Middleware
func RequestIDValue ¶ added in v0.1.1
func RequestIDWithConfig ¶ added in v0.1.1
func RequestIDWithConfig(config RequestIDConfig) zinc.Middleware
func RequestLogger ¶ added in v0.0.73
func RequestLogger() zinc.Middleware
RequestLogger creates request-logging middleware with default settings.
func RequestLoggerWithConfig ¶ added in v0.0.73
func RequestLoggerWithConfig(config RequestLoggerConfig) zinc.Middleware
RequestLoggerWithConfig creates request-logging middleware with custom settings.
func Rewrite ¶ added in v0.1.1
func Rewrite(from, to string) zinc.Middleware
func RewriteWithConfig ¶ added in v0.1.1
func RewriteWithConfig(config RewriteConfig) zinc.Middleware
func RewriteWithRules ¶ added in v0.1.1
func RewriteWithRules(rules map[string]string) zinc.Middleware
func RouteHeaders ¶ added in v0.1.2
func RouteHeaders(rules ...HeaderRoute) zinc.Middleware
func Secure ¶ added in v0.1.1
func Secure() zinc.Middleware
func SecureWithConfig ¶ added in v0.1.1
func SecureWithConfig(config SecureConfig) zinc.Middleware
func SessionCookie ¶ added in v0.1.1
func SessionCookie(name, secret string) zinc.Middleware
func SessionWithConfig ¶ added in v0.1.1
func SessionWithConfig(config SessionConfig) zinc.Middleware
func SetHeader ¶ added in v0.1.2
func SetHeader(key, value string) zinc.Middleware
func Static ¶ added in v0.1.1
func Static(root string) zinc.Middleware
func StaticFrom ¶ added in v0.1.1
func StaticFrom(prefix, root string) zinc.Middleware
func StaticWithConfig ¶ added in v0.1.1
func StaticWithConfig(config StaticConfig) zinc.Middleware
func Throttle ¶ added in v0.1.2
func Throttle(limit int) zinc.Middleware
func TrailingSlash ¶ added in v0.1.1
func TrailingSlash() zinc.Middleware
func TrailingSlashWithConfig ¶ added in v0.1.1
func TrailingSlashWithConfig(config TrailingSlashConfig) zinc.Middleware
Types ¶
type BasicAuthConfig ¶ added in v0.0.80
type BasicAuthConfig struct {
Skipper func(*zinc.Context) bool
Extractor BasicAuthExtractor
Validator BasicAuthValidator
SuccessHandler zinc.RouteHandler
ErrorHandler BasicAuthErrorHandler
Realm string
}
func DefaultBasicAuthConfig ¶ added in v0.0.80
func DefaultBasicAuthConfig() BasicAuthConfig
type BasicAuthCredentials ¶ added in v0.0.80
type BasicAuthCredentials struct {
Username string
Password string
Source BasicAuthSource
}
type BasicAuthErrorHandler ¶ added in v0.0.80
type BasicAuthExtractor ¶ added in v0.0.80
type BasicAuthExtractor func(*zinc.Context) (BasicAuthCredentials, error)
func BasicAuthFromAuthorizationHeader ¶ added in v0.0.80
func BasicAuthFromAuthorizationHeader() BasicAuthExtractor
func BasicAuthFromFirst ¶ added in v0.0.80
func BasicAuthFromFirst(extractors ...BasicAuthExtractor) BasicAuthExtractor
func BasicAuthFromHeader ¶ added in v0.0.80
func BasicAuthFromHeader(header string) BasicAuthExtractor
func BasicAuthFromHeaderPrefix ¶ added in v0.0.80
func BasicAuthFromHeaderPrefix(header, prefix string) BasicAuthExtractor
type BasicAuthIdentity ¶ added in v0.0.80
type BasicAuthIdentity struct {
Username string
Source BasicAuthSource
}
func BasicAuthCurrent ¶ added in v0.0.80
func BasicAuthCurrent(c *zinc.Context) (BasicAuthIdentity, bool)
func MustBasicAuthCurrent ¶ added in v0.0.80
func MustBasicAuthCurrent(c *zinc.Context) BasicAuthIdentity
type BasicAuthPair ¶ added in v0.0.80
type BasicAuthSource ¶ added in v0.0.80
type BasicAuthSource string
const ( BasicAuthSourceAuthorizationHeader BasicAuthSource = "authorization_header" BasicAuthSourceHeader BasicAuthSource = "header" )
type BasicAuthValidator ¶ added in v0.0.80
type BasicAuthValidator func(*zinc.Context, BasicAuthCredentials) (bool, error)
func BasicAuthStatic ¶ added in v0.0.80
func BasicAuthStatic(username, password string) BasicAuthValidator
func BasicAuthStaticPairs ¶ added in v0.0.80
func BasicAuthStaticPairs(pairs ...BasicAuthPair) BasicAuthValidator
type BodyDumpConfig ¶ added in v0.0.80
type BodyDumpConfig struct {
Skipper func(*zinc.Context) bool
Observe BodyDumpObserver
Redact BodyDumpRedactor
MaxRequestBytes int64
MaxResponseBytes int64
}
func DefaultBodyDumpConfig ¶ added in v0.0.80
func DefaultBodyDumpConfig() BodyDumpConfig
type BodyDumpObserver ¶ added in v0.0.80
type BodyDumpObserver func(*zinc.Context, BodyDumpSnapshot)
type BodyDumpRedactor ¶ added in v0.0.80
type BodyDumpRedactor func(*zinc.Context, *BodyDumpSnapshot)
type BodyDumpSnapshot ¶ added in v0.0.80
type BodyLimitConfig ¶ added in v0.0.80
type BodyLimitError ¶ added in v0.0.80
type BodyLimitError struct {
Limit int64
Observed int64
Source BodyLimitSource
}
func (*BodyLimitError) Error ¶ added in v0.0.80
func (e *BodyLimitError) Error() string
func (*BodyLimitError) Is ¶ added in v0.0.80
func (e *BodyLimitError) Is(target error) bool
func (*BodyLimitError) Unwrap ¶ added in v0.0.80
func (e *BodyLimitError) Unwrap() error
type BodyLimitSource ¶ added in v0.0.80
type BodyLimitSource string
const ( BodyLimitSourceContentLength BodyLimitSource = "content_length" BodyLimitSourceBodyRead BodyLimitSource = "body_read" )
type CORSConfig ¶ added in v0.0.80
type CORSConfig struct {
AllowOrigins []string
AllowMethods []string
AllowHeaders []string
ExposeHeaders []string
AllowCredentials bool
MaxAge int
Skipper func(*zinc.Context) bool
}
func DefaultCORSConfig ¶ added in v0.0.80
func DefaultCORSConfig() CORSConfig
type CORSOption ¶ added in v0.0.80
type CORSOption func(*CORSConfig)
func CORSAllowCredentials ¶ added in v0.0.80
func CORSAllowCredentials(allow bool) CORSOption
func CORSAllowHeaders ¶ added in v0.0.80
func CORSAllowHeaders(headers ...string) CORSOption
func CORSAllowMethods ¶ added in v0.0.80
func CORSAllowMethods(methods ...string) CORSOption
func CORSAllowOrigins ¶ added in v0.0.80
func CORSAllowOrigins(origins ...string) CORSOption
func CORSExposeHeaders ¶ added in v0.0.80
func CORSExposeHeaders(headers ...string) CORSOption
func CORSMaxAge ¶ added in v0.0.80
func CORSMaxAge(maxAge time.Duration) CORSOption
func CORSMaxAgeSeconds ¶ added in v0.0.80
func CORSMaxAgeSeconds(seconds int) CORSOption
func CORSSkipper ¶ added in v0.0.80
func CORSSkipper(skipper func(*zinc.Context) bool) CORSOption
type CSRFConfig ¶ added in v0.0.80
type CSRFConfig struct {
Skipper func(*zinc.Context) bool
Readers []CSRFReader
Generate CSRFGenerator
TokenBytes int
Cookie CSRFCookie
ExposeHeader string
TrustedOrigins []string
AllowFetchSite CSRFFetchSiteDecider
ErrorHandler CSRFErrorHandler
}
func DefaultCSRFConfig ¶ added in v0.0.80
func DefaultCSRFConfig() CSRFConfig
type CSRFCookie ¶ added in v0.0.80
type CSRFDecision ¶ added in v0.0.80
type CSRFDecision struct {
Site CSRFFetchSite
Origin string
Trusted bool
}
type CSRFFetchSite ¶ added in v0.0.80
type CSRFFetchSite string
const ( CSRFFetchSiteSameOrigin CSRFFetchSite = "same-origin" CSRFFetchSiteSameSite CSRFFetchSite = "same-site" CSRFFetchSiteCrossSite CSRFFetchSite = "cross-site" CSRFFetchSiteNone CSRFFetchSite = "none" )
type CSRFFetchSiteDecider ¶ added in v0.0.80
type CSRFFetchSiteDecider func(*zinc.Context, CSRFDecision) (bool, error)
type CSRFReader ¶ added in v0.0.80
func CSRFFromFirst ¶ added in v0.0.80
func CSRFFromFirst(readers ...CSRFReader) CSRFReader
func CSRFFromForm ¶ added in v0.0.80
func CSRFFromForm(name string) CSRFReader
func CSRFFromHeader ¶ added in v0.0.80
func CSRFFromHeader(header string) CSRFReader
func CSRFFromQuery ¶ added in v0.0.80
func CSRFFromQuery(name string) CSRFReader
type CSRFReason ¶ added in v0.0.80
type CSRFReason string
const ( CSRFReasonTokenMissing CSRFReason = "token_missing" CSRFReasonCookieMissing CSRFReason = "cookie_missing" CSRFReasonTokenInvalid CSRFReason = "token_invalid" CSRFReasonFetchSiteRejected CSRFReason = "fetch_site_rejected" )
type CSRFState ¶ added in v0.0.80
type CSRFState struct {
Token string
CookieName string
Issued bool
Verified bool
FetchSite CSRFFetchSite
}
func MustCSRFCurrent ¶ added in v0.0.80
type CSRFViolation ¶ added in v0.0.80
type CSRFViolation struct {
Reason CSRFReason
CookieName string
FetchSite CSRFFetchSite
Origin string
Cause error
}
func (*CSRFViolation) Error ¶ added in v0.0.80
func (e *CSRFViolation) Error() string
func (*CSRFViolation) Is ¶ added in v0.0.80
func (e *CSRFViolation) Is(target error) bool
func (*CSRFViolation) Unwrap ¶ added in v0.0.80
func (e *CSRFViolation) Unwrap() error
type CasbinAuthConfig ¶ added in v0.1.1
type CasbinAuthConfig struct {
Skipper func(*zinc.Context) bool
Enforcer CasbinEnforcer
Subject CasbinValueFunc
Object CasbinValueFunc
Action CasbinValueFunc
SuccessHandler zinc.RouteHandler
ErrorHandler CasbinErrorHandler
}
type CasbinEnforcer ¶ added in v0.1.1
type CasbinValueFunc ¶ added in v0.1.1
func CasbinActionMethod ¶ added in v0.1.1
func CasbinActionMethod() CasbinValueFunc
func CasbinObjectPath ¶ added in v0.1.1
func CasbinObjectPath() CasbinValueFunc
func CasbinSubjectFromBasicAuth ¶ added in v0.1.1
func CasbinSubjectFromBasicAuth() CasbinValueFunc
func CasbinSubjectFromContext ¶ added in v0.1.1
func CasbinSubjectFromContext(key any) CasbinValueFunc
func CasbinSubjectFromKeyAuth ¶ added in v0.1.1
func CasbinSubjectFromKeyAuth() CasbinValueFunc
type ContextTimeoutConfig ¶ added in v0.0.80
type ContextTimeoutError ¶ added in v0.0.80
type ContextTimeoutError struct {
Info ContextTimeoutInfo
Cause error
}
func (*ContextTimeoutError) Error ¶ added in v0.0.80
func (e *ContextTimeoutError) Error() string
func (*ContextTimeoutError) Is ¶ added in v0.0.80
func (e *ContextTimeoutError) Is(target error) bool
func (*ContextTimeoutError) Unwrap ¶ added in v0.0.80
func (e *ContextTimeoutError) Unwrap() error
type ContextTimeoutErrorHandler ¶ added in v0.0.80
type ContextTimeoutErrorHandler func(*zinc.Context, *ContextTimeoutError) error
type ContextTimeoutInfo ¶ added in v0.0.80
func ContextTimeoutCurrent ¶ added in v0.0.80
func ContextTimeoutCurrent(c *zinc.Context) (ContextTimeoutInfo, bool)
func MustContextTimeoutCurrent ¶ added in v0.0.80
func MustContextTimeoutCurrent(c *zinc.Context) ContextTimeoutInfo
type DecompressConfig ¶ added in v0.1.1
type GzipConfig ¶ added in v0.1.1
type HeaderRoute ¶ added in v0.1.2
type HeaderRoute struct {
Header string
Value string
Middleware zinc.Middleware
}
type JWTConfig ¶ added in v0.0.80
type JWTConfig struct {
Skipper func(*zinc.Context) bool
Extractor JWTExtractor
NewClaims func(*zinc.Context) jwtgo.Claims
KeyFunc JWTKeyFunc
ParseTokenFunc JWTParseTokenFunc
ParserOptions []jwtgo.ParserOption
Validate JWTValidateFunc
SuccessHandler zinc.RouteHandler
ErrorHandler JWTErrorHandler
Realm string
}
func DefaultJWTConfig ¶ added in v0.0.80
func DefaultJWTConfig() JWTConfig
type JWTExtractor ¶ added in v0.0.80
func JWTFromAuthHeader ¶ added in v0.0.80
func JWTFromAuthHeader(scheme string) JWTExtractor
func JWTFromCookie ¶ added in v0.0.80
func JWTFromCookie(name string) JWTExtractor
func JWTFromFirst ¶ added in v0.0.80
func JWTFromFirst(extractors ...JWTExtractor) JWTExtractor
func JWTFromHeader ¶ added in v0.0.80
func JWTFromHeader(header string) JWTExtractor
func JWTFromHeaderPrefix ¶ added in v0.0.80
func JWTFromHeaderPrefix(header, prefix string) JWTExtractor
func JWTFromQuery ¶ added in v0.0.80
func JWTFromQuery(name string) JWTExtractor
type JWTParseTokenFunc ¶ added in v0.0.80
type JWTValidateFunc ¶ added in v0.0.80
type JaegerConfig ¶ added in v0.1.1
type JaegerConfig struct {
Skipper func(*zinc.Context) bool
Observe JaegerObserver
Operation JaegerOperationName
Now func() time.Time
}
type JaegerObserver ¶ added in v0.1.1
type JaegerObserver func(*zinc.Context, JaegerSpan) error
type JaegerOperationName ¶ added in v0.1.1
type JaegerSpan ¶ added in v0.1.1
type JaegerSpan struct {
TraceID string
SpanID string
ParentSpanID string
Flags string
Operation string
StartTime time.Time
Duration time.Duration
Error error
}
func JaegerCurrent ¶ added in v0.1.1
func JaegerCurrent(c *zinc.Context) (JaegerSpan, bool)
type KeyAuthConfig ¶ added in v0.1.1
type KeyAuthConfig struct {
Skipper func(*zinc.Context) bool
Extractor KeyAuthExtractor
Validator KeyAuthValidator
SuccessHandler zinc.RouteHandler
ErrorHandler KeyAuthErrorHandler
}
func DefaultKeyAuthConfig ¶ added in v0.1.1
func DefaultKeyAuthConfig() KeyAuthConfig
type KeyAuthCredentials ¶ added in v0.1.1
type KeyAuthCredentials struct {
Key string
Source KeyAuthSource
}
type KeyAuthErrorHandler ¶ added in v0.1.1
type KeyAuthExtractor ¶ added in v0.1.1
type KeyAuthExtractor func(*zinc.Context) (KeyAuthCredentials, error)
func KeyAuthFromAuthorizationHeader ¶ added in v0.1.1
func KeyAuthFromAuthorizationHeader() KeyAuthExtractor
func KeyAuthFromCookie ¶ added in v0.1.1
func KeyAuthFromCookie(name string) KeyAuthExtractor
func KeyAuthFromFirst ¶ added in v0.1.1
func KeyAuthFromFirst(extractors ...KeyAuthExtractor) KeyAuthExtractor
func KeyAuthFromHeader ¶ added in v0.1.1
func KeyAuthFromHeader(header string) KeyAuthExtractor
func KeyAuthFromHeaderPrefix ¶ added in v0.1.1
func KeyAuthFromHeaderPrefix(header, prefix string) KeyAuthExtractor
func KeyAuthFromQuery ¶ added in v0.1.1
func KeyAuthFromQuery(name string) KeyAuthExtractor
type KeyAuthSource ¶ added in v0.1.1
type KeyAuthSource string
const ( KeyAuthSourceAuthorizationHeader KeyAuthSource = "authorization_header" KeyAuthSourceHeader KeyAuthSource = "header" KeyAuthSourceQuery KeyAuthSource = "query" KeyAuthSourceCookie KeyAuthSource = "cookie" )
type KeyAuthState ¶ added in v0.1.1
type KeyAuthState struct {
Key string
Source KeyAuthSource
}
func KeyAuthCurrent ¶ added in v0.1.1
func KeyAuthCurrent(c *zinc.Context) (KeyAuthState, bool)
func MustKeyAuthCurrent ¶ added in v0.1.1
func MustKeyAuthCurrent(c *zinc.Context) KeyAuthState
type KeyAuthValidator ¶ added in v0.1.1
type KeyAuthValidator func(*zinc.Context, KeyAuthCredentials) (bool, error)
func KeyAuthStatic ¶ added in v0.1.1
func KeyAuthStatic(key string) KeyAuthValidator
func KeyAuthStaticKeys ¶ added in v0.1.1
func KeyAuthStaticKeys(keys ...string) KeyAuthValidator
type MethodOverrideConfig ¶ added in v0.1.1
type MethodOverrideGetter ¶ added in v0.1.1
func MethodOverrideFromFirst ¶ added in v0.1.1
func MethodOverrideFromFirst(getters ...MethodOverrideGetter) MethodOverrideGetter
func MethodOverrideFromHeader ¶ added in v0.1.1
func MethodOverrideFromHeader(header string) MethodOverrideGetter
func MethodOverrideFromQuery ¶ added in v0.1.1
func MethodOverrideFromQuery(name string) MethodOverrideGetter
type PrometheusConfig ¶ added in v0.1.1
type PrometheusMetrics ¶ added in v0.1.1
type PrometheusMetrics struct {
// contains filtered or unexported fields
}
func NewPrometheusMetrics ¶ added in v0.1.1
func NewPrometheusMetrics() *PrometheusMetrics
func (*PrometheusMetrics) Observe ¶ added in v0.1.1
func (m *PrometheusMetrics) Observe(method, route string, status int, duration time.Duration)
func (*PrometheusMetrics) Text ¶ added in v0.1.1
func (m *PrometheusMetrics) Text() string
type ProxyBalancer ¶ added in v0.1.2
type ProxyBalancer interface {
Next(*zinc.Context) (*ProxyTarget, error)
}
func NewRandomBalancer ¶ added in v0.1.2
func NewRandomBalancer(targets []*ProxyTarget) ProxyBalancer
func NewRoundRobinBalancer ¶ added in v0.1.2
func NewRoundRobinBalancer(targets []*ProxyTarget) ProxyBalancer
type ProxyConfig ¶ added in v0.1.1
type ProxyConfig struct {
Skipper func(*zinc.Context) bool
Target string
Targets []*ProxyTarget
Balancer ProxyBalancer
Director func(*http.Request)
Modify func(*http.Response) error
ModifyResponse func(*http.Response) error
ErrorHandler func(http.ResponseWriter, *http.Request, error)
Retries int
RetryFilter func(*zinc.Context, error) bool
Rewrite map[string]string
RegexRewrite map[*regexp.Regexp]string
Transport http.RoundTripper
}
type ProxyTarget ¶ added in v0.1.2
type RateLimiterConfig ¶
type RateLimiterConfig struct {
// Rate is the token refill rate per second
Rate float64
// Capacity is the maximum number of tokens in the bucket
Capacity float64
// IPLookup is the function to extract IP address for per-IP rate limiting
// If nil, the rate limiter applies globally
IPLookup func(*zinc.Context) string
// KeyGenerator is a custom function to generate keys for rate limiting
// If nil and IPLookup is set, IP is used as key
// If both nil, global rate limiting is used
KeyGenerator func(*zinc.Context) string
// StatusCode is the response code when rate limit is exceeded
StatusCode int
// LimitReachedHandler is called when rate limit is reached
LimitReachedHandler zinc.RouteHandler
}
RateLimiterConfig contains configuration for the rate limiter middleware
type RecoverConfig ¶ added in v0.1.1
type RecoverConfig struct {
Skipper func(*zinc.Context) bool
Handler RecoverHandler
StackSize int
DisableStack bool
}
func DefaultRecoverConfig ¶ added in v0.1.1
func DefaultRecoverConfig() RecoverConfig
type RecoverError ¶ added in v0.1.1
func (*RecoverError) Error ¶ added in v0.1.1
func (e *RecoverError) Error() string
type RecoverHandler ¶ added in v0.1.1
type RecoverHandler func(*zinc.Context, *RecoverError) error
type RedirectConfig ¶ added in v0.1.1
type RequestIDConfig ¶ added in v0.1.1
type RequestIDConfig struct {
Skipper func(*zinc.Context) bool
Header string
Generator RequestIDGenerator
}
func DefaultRequestIDConfig ¶ added in v0.1.1
func DefaultRequestIDConfig() RequestIDConfig
type RequestIDGenerator ¶ added in v0.1.1
func StaticRequestID ¶ added in v0.1.1
func StaticRequestID(id string) RequestIDGenerator
type RequestIDState ¶ added in v0.1.1
func MustRequestIDCurrent ¶ added in v0.1.1
func MustRequestIDCurrent(c *zinc.Context) RequestIDState
func RequestIDCurrent ¶ added in v0.1.1
func RequestIDCurrent(c *zinc.Context) (RequestIDState, bool)
type RequestLoggerConfig ¶ added in v0.0.73
type RequestLoggerConfig struct {
// Skipper skips logging when it returns true.
Skipper func(*zinc.Context) bool
// BeforeNextFunc runs before the rest of the middleware/handler chain.
BeforeNextFunc func(*zinc.Context)
// LogValuesFunc receives extracted values and should emit logs.
// If nil, a default slog logger implementation is used.
LogValuesFunc func(*zinc.Context, RequestLoggerValues) error
// HandleError forwards returned errors through zinc's error handler before logging.
HandleError bool
// Logger is used by the default LogValuesFunc. If nil, slog.Default() is used.
Logger *slog.Logger
LogLatency bool
LogMethod bool
LogURI bool
LogRoutePath bool
LogStatus bool
LogError bool
LogRemoteIP bool
LogHost bool
LogUserAgent bool
LogRequestID bool
LogContentLength bool
LogResponseSize bool
LogHeaders []string
LogQueryParams []string
// contains filtered or unexported fields
}
RequestLoggerConfig controls request logging behavior.
func DefaultRequestLoggerConfig ¶ added in v0.0.73
func DefaultRequestLoggerConfig() RequestLoggerConfig
DefaultRequestLoggerConfig returns default request-logger settings.
type RequestLoggerValues ¶ added in v0.0.73
type RequestLoggerValues struct {
StartTime time.Time
Latency time.Duration
Method string
URI string
RoutePath string
Status int
Error error
RemoteIP string
Host string
UserAgent string
RequestID string
ContentLength string
ResponseSize int64
Headers map[string][]string
QueryParams map[string][]string
}
RequestLoggerValues contains extracted request/response values.
type RewriteConfig ¶ added in v0.1.1
type SecureConfig ¶ added in v0.1.1
type SecureConfig struct {
Skipper func(*zinc.Context) bool
XSSProtection string
ContentTypeNosniff string
XFrameOptions string
HSTSMaxAge int
HSTSExcludeSubdomains bool
ContentSecurityPolicy string
ContentSecurityPolicyReportOnly string
ReferrerPolicy string
CrossOriginResourcePolicy string
PermissionsPolicy string
}
func DefaultSecureConfig ¶ added in v0.1.1
func DefaultSecureConfig() SecureConfig
type Session ¶ added in v0.1.1
type Session struct {
// contains filtered or unexported fields
}
func MustSession ¶ added in v0.1.1
type SessionConfig ¶ added in v0.1.1
type SessionConfig struct {
Skipper func(*zinc.Context) bool
Name string
Secret []byte
Path string
Domain string
MaxAge int
Secure bool
HTTPOnly bool
DisableHTTPOnly bool
SameSite http.SameSite
}
func DefaultSessionConfig ¶ added in v0.1.1
func DefaultSessionConfig() SessionConfig
type StaticConfig ¶ added in v0.1.1
type TokenBucket ¶
type TokenBucket struct {
// contains filtered or unexported fields
}
TokenBucket represents a simple token bucket rate limiter
Source Files
¶
- basic_auth.go
- body_dump.go
- body_limit.go
- casbin_auth.go
- context_timeout.go
- cors.go
- csrf.go
- decompress.go
- gzip.go
- jaeger.go
- jwt.go
- key_auth.go
- method_override.go
- pprof.go
- prometheus.go
- proxy.go
- ratelimiter.go
- recover.go
- redirect.go
- request_id.go
- request_logger.go
- rewrite.go
- secure.go
- session.go
- static.go
- trailing_slash.go
- utility.go