middleware

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BodyDumpDefaultMaxRequestBytes  int64 = 1 << 20
	BodyDumpDefaultMaxResponseBytes int64 = 1 << 20
)
View Source
const (
	B  int64 = 1
	KB       = 1024 * B
	MB       = 1024 * KB
	GB       = 1024 * MB
)
View Source
const (
	HeaderXHTTPMethodOverride = "X-HTTP-Method-Override"
	HeaderXOriginalMethod     = "X-Original-Method"
)
View Source
const HeaderUberTraceID = "Uber-Trace-Id"

Variables

View Source
var (
	ErrBasicAuthCredentialsMissing   = errors.New("zincbasicauth: credentials missing")
	ErrBasicAuthCredentialsMalformed = errors.New("zincbasicauth: credentials malformed")
	ErrBasicAuthCredentialsInvalid   = errors.New("zincbasicauth: credentials invalid")
)
View Source
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")
)
View Source
var (
	ErrDecompressUnsupportedEncoding = errors.New("zincdecompress: unsupported content encoding")
	ErrDecompressInvalidBody         = errors.New("zincdecompress: invalid compressed body")
)
View Source
var (
	ErrJWTTokenMissing   = errors.New("zincjwt: token missing")
	ErrJWTTokenMalformed = errors.New("zincjwt: token malformed")
	ErrJWTTokenInvalid   = errors.New("zincjwt: token invalid")
)
View Source
var (
	ErrKeyAuthKeyMissing = errors.New("zinckeyauth: key missing")
	ErrKeyAuthKeyInvalid = errors.New("zinckeyauth: key invalid")
)
View Source
var ErrBodyLimitExceeded = errors.New("zincbodylimit: request body exceeded configured limit")
View Source
var ErrCasbinAuthRejected = errors.New("zinccasbin: request rejected")
View Source
var ErrContextTimeout = errors.New("zinccontexttimeout: request context deadline exceeded")
View Source
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 BasicAuthUsername added in v0.0.80

func BasicAuthUsername(c *zinc.Context) (string, bool)

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 CSRFToken added in v0.0.80

func CSRFToken(c *zinc.Context) (string, bool)

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 ContextTimeoutRemaining(c *zinc.Context) (time.Duration, bool)

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 JWTClaims added in v0.0.80

func JWTClaims[T any](c *zinc.Context) (T, bool)

func JWTToken added in v0.0.80

func JWTToken(c *zinc.Context) (*jwtgo.Token, bool)

func JWTTokenString added in v0.0.80

func JWTTokenString(c *zinc.Context) (string, bool)

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 Logger added in v0.0.73

func Logger() zinc.Middleware

Logger is an alias for RequestLogger.

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 MustBasicAuthUsername(c *zinc.Context) string

func MustCSRFToken added in v0.0.80

func MustCSRFToken(c *zinc.Context) string

func MustJWTClaims added in v0.0.80

func MustJWTClaims[T any](c *zinc.Context) T

func MustJWTToken added in v0.0.80

func MustJWTToken(c *zinc.Context) *jwtgo.Token

func MustJWTTokenString added in v0.0.80

func MustJWTTokenString(c *zinc.Context) string

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 RandomRequestID added in v0.1.1

func RandomRequestID(*zinc.Context) (string, error)

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 Redirect added in v0.1.1

func Redirect(from, to string, statusCode ...int) 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 RequestIDValue(c *zinc.Context) string

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 StaticFS added in v0.1.1

func StaticFS(filesystem fs.FS) 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 BasicAuthErrorHandler func(*zinc.Context, error) error

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 BasicAuthPair struct {
	Username string
	Password string
}

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 BodyDumpSnapshot struct {
	Method            string
	Path              string
	RoutePath         string
	Status            int
	RequestBody       []byte
	ResponseBody      []byte
	RequestBytes      int64
	ResponseBytes     int64
	RequestTruncated  bool
	ResponseTruncated bool
	Error             error
}

type BodyLimitConfig added in v0.0.80

type BodyLimitConfig struct {
	Skipper func(*zinc.Context) bool
	Limit   int64
}

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 CSRFCookie struct {
	Name     string
	Domain   string
	Path     string
	MaxAge   int
	Secure   bool
	HTTPOnly bool
	SameSite http.SameSite
}

type CSRFDecision added in v0.0.80

type CSRFDecision struct {
	Site    CSRFFetchSite
	Origin  string
	Trusted bool
}

type CSRFErrorHandler added in v0.0.80

type CSRFErrorHandler func(*zinc.Context, error) error

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 CSRFGenerator added in v0.0.80

type CSRFGenerator func(*zinc.Context) (string, error)

type CSRFReader added in v0.0.80

type CSRFReader func(*zinc.Context) ([]string, error)

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 CSRFCurrent added in v0.0.80

func CSRFCurrent(c *zinc.Context) (CSRFState, bool)

func MustCSRFCurrent added in v0.0.80

func MustCSRFCurrent(c *zinc.Context) CSRFState

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 CasbinEnforcer interface {
	Enforce(args ...any) (bool, error)
}

type CasbinErrorHandler added in v0.1.1

type CasbinErrorHandler func(*zinc.Context, error) error

type CasbinValueFunc added in v0.1.1

type CasbinValueFunc func(*zinc.Context) any

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 ContextTimeoutConfig struct {
	Skipper      func(*zinc.Context) bool
	Timeout      time.Duration
	ErrorHandler ContextTimeoutErrorHandler
}

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

type ContextTimeoutInfo struct {
	Timeout  time.Duration
	Deadline time.Time
}

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 DecompressConfig struct {
	Skipper             func(*zinc.Context) bool
	MaxDecompressedSize int64
}

type GzipConfig added in v0.1.1

type GzipConfig struct {
	Skipper   func(*zinc.Context) bool
	Level     int
	MinLength int
}

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 JWTErrorHandler added in v0.0.80

type JWTErrorHandler func(*zinc.Context, error) error

type JWTExtractor added in v0.0.80

type JWTExtractor func(*zinc.Context) (string, error)

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 JWTKeyFunc added in v0.0.80

type JWTKeyFunc func(*zinc.Context, *jwtgo.Token) (any, error)

type JWTParseTokenFunc added in v0.0.80

type JWTParseTokenFunc func(*zinc.Context, string) (*jwtgo.Token, error)

type JWTValidateFunc added in v0.0.80

type JWTValidateFunc func(*zinc.Context, *jwtgo.Token) error

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 JaegerOperationName func(*zinc.Context) string

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 KeyAuthErrorHandler func(*zinc.Context, error) error

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 MethodOverrideConfig struct {
	Skipper       func(*zinc.Context) bool
	Getter        MethodOverrideGetter
	SourceMethods []string
	Methods       []string
}

type MethodOverrideGetter added in v0.1.1

type MethodOverrideGetter func(*zinc.Context) string

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 PrometheusConfig struct {
	Skipper func(*zinc.Context) bool
	Metrics *PrometheusMetrics
	Now     func() time.Time
}

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 ProxyTarget struct {
	Name string
	URL  *url.URL
}

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

type RecoverError struct {
	Value any
	Stack []byte
}

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 RedirectConfig struct {
	Skipper    func(*zinc.Context) bool
	Rules      map[string]string
	StatusCode int
}

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

type RequestIDGenerator func(*zinc.Context) (string, error)

func StaticRequestID added in v0.1.1

func StaticRequestID(id string) RequestIDGenerator

type RequestIDState added in v0.1.1

type RequestIDState struct {
	ID        string
	Header    string
	Generated bool
}

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 RewriteConfig struct {
	Skipper func(*zinc.Context) bool
	Rules   map[string]string
}

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

func MustSession(c *zinc.Context) *Session

func SessionCurrent added in v0.1.1

func SessionCurrent(c *zinc.Context) (*Session, bool)

func (*Session) Delete added in v0.1.1

func (s *Session) Delete(key string)

func (*Session) Get added in v0.1.1

func (s *Session) Get(key string) string

func (*Session) Set added in v0.1.1

func (s *Session) Set(key, value string)

func (*Session) Values added in v0.1.1

func (s *Session) Values() map[string]string

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 StaticConfig struct {
	Skipper        func(*zinc.Context) bool
	Filesystem     fs.FS
	Root           string
	Prefix         string
	NextOnNotFound bool
}

type TokenBucket

type TokenBucket struct {
	// contains filtered or unexported fields
}

TokenBucket represents a simple token bucket rate limiter

type TrailingSlashConfig added in v0.1.1

type TrailingSlashConfig struct {
	Skipper    func(*zinc.Context) bool
	Add        bool
	Redirect   bool
	StatusCode int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL