middleware

package
v1.2.11 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: MIT Imports: 30 Imported by: 5

Documentation

Index

Examples

Constants

View Source
const (
	AccessLogStartKey = "X_ACCESS_START"
	AccessLogEndKey   = "X_ACCESS_END"
)
View Source
const (
	AuthCookieName             = "X_AUTH"
	AuthRedirectOriginURLQuery = "origin"
)
View Source
const (
	DigestAuthCtxKey = "X_DIGEST" // Key for digest parameters saved in context
	DigestAuthPrefix = "Digest "  // Digest Authentication Prefix
)
View Source
const (
	TokenAttrKey    = "X_TOKEN"
	TokenParamName  = "_token_"
	TokenHeaderName = "X-CSRF-TOKEN" //nolint: gosec
	TokenCookieName = "X_TOKEN"
)
View Source
const AccessLogJSONFormat = `` /* 191-byte string literal not displayed */

AccessLogJSONFormat default json log format

View Source
const AccessLogTextFormat = "text:%t\t%S\t%D\t%B\t%c\t%r\t%m\t%s://%h%u\t%h{User-Agent}%n"

AccessLogTextFormat default text log format TIME STATUS LATENCY SIZE CLIENT_IP REMOTE_ADDR METHOD HOST URL HEADER(User-Agent)

View Source
const AccessLogTimeFormat = "2006-01-02T15:04:05.000Z07:00"

AccessLogTimeFormat default log time format

View Source
const (
	AuthUserKey = "X_AUTH_USER" // Key for authenticated user object saved in context
)
View Source
const (
	BasicAuthPrefix = "Basic " // Basic Authentication Prefix
)
View Source
const (
	BearerAuthPrefix = "Bearer " // Bearer Authentication Prefix
)
View Source
const HTTPDumpKey = "X_DUMP"

HTTPDumpKey is the key for dump http saved in context

Variables

View Source
var (
	// LocaleParamNames default parameter key names
	LocaleParamNames = []string{"_locale_"}

	// LocaleCookieNames default cookie names
	LocaleCookieNames = []string{"X_LOCALE"}

	// LocaleHeaderNames default http header names
	LocaleHeaderNames = []string{"Accept-Language"}
)

Functions

This section is empty.

Types

type AccessLogJSONWriter

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

AccessLogJSONWriter format(json-style) and write access log

func NewAccessLogJSONWriter

func NewAccessLogJSONWriter(writer io.Writer, format string) *AccessLogJSONWriter

NewAccessLogJSONWriter create json style writer for AccessLogger

func (*AccessLogJSONWriter) SetFormat

func (aljw *AccessLogJSONWriter) SetFormat(format string)

SetFormat set the access alw format

func (*AccessLogJSONWriter) SetOutput

func (aljw *AccessLogJSONWriter) SetOutput(w io.Writer)

SetOutput set the access log writer

func (*AccessLogJSONWriter) Write

func (aljw *AccessLogJSONWriter) Write(c *xin.Context)

Write write the access log

type AccessLogMultiWriter

type AccessLogMultiWriter struct {
	Writers []AccessLogWriter
}

AccessLogMultiWriter write log to multiple writers.

func NewAccessLogMultiWriter

func NewAccessLogMultiWriter(ws ...AccessLogWriter) *AccessLogMultiWriter

NewAccessLogMultiWriter create a multi writer

func (*AccessLogMultiWriter) Write

func (mw *AccessLogMultiWriter) Write(c *xin.Context)

Write write the access log to multiple writers.

type AccessLogTextWriter

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

AccessLogTextWriter format(text) and write access log

func NewAccessLogTextWriter

func NewAccessLogTextWriter(writer io.Writer, format string) *AccessLogTextWriter

NewAccessLogTextWriter create text style writer for AccessLogger

func (*AccessLogTextWriter) SetFormat

func (altw *AccessLogTextWriter) SetFormat(format string)

SetFormat set the access alw format

func (*AccessLogTextWriter) SetOutput

func (altw *AccessLogTextWriter) SetOutput(w io.Writer)

SetOutput set the access log writer

func (*AccessLogTextWriter) Write

func (altw *AccessLogTextWriter) Write(c *xin.Context)

Write write the access log

type AccessLogWriter

type AccessLogWriter interface {
	Write(*xin.Context)
}

AccessLogWriter access log writer for XIN

%t{format} - Request start time, if {format} is omitted, '2006-01-02T15:04:05.000Z07:00' is used.
%c - Client IP ([X-Forwarded-For, X-Real-Ip] or RemoteIP())
%r - Remote IP:Port (%a)
%u - Request URL
%p - Request protocol
%s - Request scheme (http, https)
%m - Request method (GET, POST, etc.)
%q - Query string (prepended with a '?' if it exists)
%h - Request host
%h{name} - Request header
%A - Server listen address
%D - Time taken to process the request, duration format string
%T - Time taken to process the request, number in milliseconds
%S - Response status code
%B - Response body length (%L)
%H - Local hostname
%H{name} - Response header
%n: EOL(Windows: "\r\n", Other: "\n")

func NewAccessLogWriter

func NewAccessLogWriter(writer io.Writer, format string) AccessLogWriter

NewAccessLogWriter create a text or json access log writer text:... -> AccessLogTextWriter json:... -> AccessLogJSONWriter

type AccessLogger

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

AccessLogger access logger middleware for XIN

Example
router := xin.New()
router.Use(NewAccessLogger(NewAccessLogWriter(os.Stdout, AccessLogTextFormat)).Handle)

router.Any("/example", func(c *xin.Context) {
	c.String(http.StatusOK, c.Request.URL.String())
})

server := &http.Server{
	Addr:    "127.0.0.1:8888",
	Handler: router,
}

go func() {
	server.ListenAndServe()
}()

time.Sleep(time.Millisecond * 100)

req, _ := http.NewRequest("GET", "http://127.0.0.1:8888/example?a=100", nil)
client := &http.Client{Timeout: time.Second * 1}
client.Do(req)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
server.Shutdown(ctx)

func DefaultAccessLogger

func DefaultAccessLogger(xin *xin.Engine) *AccessLogger

DefaultAccessLogger create a access logger middleware for XIN Equals: NewAccessLogger(NewAccessLogTextWriter(xin.Logger.GetOutputer("XAL", log.LevelTrace), AccessLogTextFormat))

func NewAccessLogger

func NewAccessLogger(writer AccessLogWriter) *AccessLogger

NewAccessLogger create a log middleware for xin access logger

func (*AccessLogger) Disable

func (al *AccessLogger) Disable(disabled bool)

Disable disable the logger or not

func (*AccessLogger) Handle

func (al *AccessLogger) Handle(c *xin.Context)

Handle process xin request

func (*AccessLogger) SetWriter

func (al *AccessLogger) SetWriter(alw AccessLogWriter)

SetWriter set the access logger writer

type AuthUser

type AuthUser interface {
	GetUsername() string
	GetPassword() string
}

AuthUser a authenticated user interface

type BasicAuth

type BasicAuth struct {
	Realm       string
	FindUser    FindUserFunc
	AuthUserKey string
	AuthPassed  func(c *xin.Context, au AuthUser)
	AuthFailed  xin.HandlerFunc
}

BasicAuth basic http authenticator

func NewBasicAuth

func NewBasicAuth(f FindUserFunc) *BasicAuth

func (*BasicAuth) Authenticate

func (ba *BasicAuth) Authenticate(c *xin.Context) (next bool, au AuthUser, err error)

func (*BasicAuth) Handle

func (ba *BasicAuth) Handle(c *xin.Context)

Handle process xin request

func (*BasicAuth) Unauthorized

func (ba *BasicAuth) Unauthorized(c *xin.Context)

Unauthorized set basic authentication WWW-Authenticate header

type BearerAuth

type BearerAuth struct {
	Realm       string
	FindUser    FindUserFunc
	AuthUserKey string
	AuthPassed  func(c *xin.Context, au AuthUser)
	AuthFailed  xin.HandlerFunc
}

BearerAuth bearer http authenticator

func NewBearerAuth

func NewBearerAuth(f FindUserFunc) *BearerAuth

func (*BearerAuth) Authenticate

func (ba *BearerAuth) Authenticate(c *xin.Context) (next bool, au AuthUser, err error)

func (*BearerAuth) Handle

func (ba *BearerAuth) Handle(c *xin.Context)

Handle process xin request

func (*BearerAuth) Unauthorized

func (ba *BearerAuth) Unauthorized(c *xin.Context)

Unauthorized set bearer authentication WWW-Authenticate header

type Compressor

type Compressor interface {
	io.Writer
	Reset(w io.Writer)
	Flush() error
	Close() error
}

type CompressorProvider

type CompressorProvider interface {
	GetCompressor() Compressor
	PutCompressor(Compressor)
}

type CookieAuth

type CookieAuth struct {
	Cryptor        cpt.Cryptor // cryptor to encode/decode cookie, MUST concurrent safe
	FindUser       FindUserFunc
	AuthUserKey    string
	RedirectURL    string
	OriginURLQuery string
	AuthPassed     func(c *xin.Context, au AuthUser)
	AuthFailed     xin.HandlerFunc

	CookieName      string
	CookieMaxAge    time.Duration
	CookieDomain    string
	CookiePath      string
	CookieSecure    bool
	CookieHttpOnly  bool
	CookieSameSite  http.SameSite
	GetCookieMaxAge func(c *xin.Context) time.Duration
}

CookieAuth cookie authenticator

func NewCookieAuth

func NewCookieAuth(f FindUserFunc, secret string) *CookieAuth

func (*CookieAuth) Authenticate

func (ca *CookieAuth) Authenticate(c *xin.Context) (next bool, au AuthUser, err error)

func (*CookieAuth) BuildRedirectURL

func (ca *CookieAuth) BuildRedirectURL(c *xin.Context) string

func (*CookieAuth) DeleteCookie

func (ca *CookieAuth) DeleteCookie(c *xin.Context)

func (*CookieAuth) GetUserPassFromCookie

func (ca *CookieAuth) GetUserPassFromCookie(c *xin.Context) (username, password string, ok bool)

func (*CookieAuth) Handle

func (ca *CookieAuth) Handle(c *xin.Context)

Handle process xin request

func (*CookieAuth) SaveUserPassToCookie

func (ca *CookieAuth) SaveUserPassToCookie(c *xin.Context, au AuthUser) error

func (*CookieAuth) SetSecret

func (ca *CookieAuth) SetSecret(secret string)

SetSecret Set the Cryptor secret

func (*CookieAuth) Unauthorized

func (ca *CookieAuth) Unauthorized(c *xin.Context)

Unauthorized redirect or abort with status 401

type DigestAuth

type DigestAuth struct {
	Realm        string
	Opaque       string
	NonceExpires time.Duration
	FindUser     FindUserFunc
	AuthUserKey  string
	AuthPassed   func(c *xin.Context, au AuthUser)
	AuthFailed   xin.HandlerFunc
	// contains filtered or unexported fields
}

DigestAuth digest http authenticator

func NewDigestAuth

func NewDigestAuth(f FindUserFunc) *DigestAuth

func (*DigestAuth) Authenticate

func (da *DigestAuth) Authenticate(c *xin.Context) (next bool, au AuthUser, err error)

func (*DigestAuth) Handle

func (da *DigestAuth) Handle(c *xin.Context)

Handle process xin request

func (*DigestAuth) Unauthorized

func (da *DigestAuth) Unauthorized(c *xin.Context)

Unauthorized set WWW-Authenticate header

func (*DigestAuth) VerifyPassword

func (da *DigestAuth) VerifyPassword(c *xin.Context, password string) (bool, error)

type FindUserFunc

type FindUserFunc func(c *xin.Context, username, password string) (AuthUser, error)

FindUserFunc user lookup function

type GzipCompressorProvider

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

func NewGzipCompressorProvider

func NewGzipCompressorProvider() *GzipCompressorProvider

func (*GzipCompressorProvider) GetCompressor

func (gcws *GzipCompressorProvider) GetCompressor() Compressor

func (*GzipCompressorProvider) NewCompressor

func (gcws *GzipCompressorProvider) NewCompressor() any

func (*GzipCompressorProvider) PutCompressor

func (gcws *GzipCompressorProvider) PutCompressor(cw Compressor)

type HTTPDumper

type HTTPDumper struct {
	Outputer   io.Writer
	Maxlength  int64
	DumpCtxKey string // use xin.Context.Set(key, true | false) to enable/disable dump
	// contains filtered or unexported fields
}

HTTPDumper dump http request and response

Example
router := xin.New()
router.Use(NewHTTPDumper(os.Stdout).Handle)

router.Any("/example", func(c *xin.Context) {
	c.String(http.StatusOK, c.Request.URL.String())
})

server := &http.Server{
	Addr:    "127.0.0.1:8888",
	Handler: router,
}

go func() {
	server.ListenAndServe()
}()

time.Sleep(time.Millisecond * 100)

req, _ := http.NewRequest("GET", "http://127.0.0.1:8888/example?a=100", nil)
client := &http.Client{Timeout: time.Second * 1}
client.Do(req)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
server.Shutdown(ctx)

func DefaultHTTPDumper

func DefaultHTTPDumper(xin *xin.Engine) *HTTPDumper

DefaultHTTPDumper create a middleware for xin http dumper Equals: NewHTTPDumper(xin.Logger.Outputer("XHD", log.LevelTrace))

func NewHTTPDumper

func NewHTTPDumper(outputer io.Writer) *HTTPDumper

NewHTTPDumper create a middleware for xin http dumper

func (*HTTPDumper) Disable

func (hd *HTTPDumper) Disable(disabled bool)

Disable disable the dumper or not

func (*HTTPDumper) Handle

func (hd *HTTPDumper) Handle(c *xin.Context)

Handle process xin request

type HTTPSRedirector

type HTTPSRedirector struct {

	// If TemporaryRedirect is true, the a 302 will be used while redirecting. Default is false (301).
	TemporaryRedirect bool

	// SSLHost is the host name that is used to redirect http requests to https. Default is "", which indicates to use the same host.
	SSLHost string
	// contains filtered or unexported fields
}

HTTPSRedirector is a middleware that helps setup a https redirect features.

func NewHTTPSRedirector

func NewHTTPSRedirector() *HTTPSRedirector

func (*HTTPSRedirector) Disable

func (sh *HTTPSRedirector) Disable(disabled bool)

Disable disable the secure handler or not

func (*HTTPSRedirector) Handle

func (sh *HTTPSRedirector) Handle(c *xin.Context)

Handle process xin request

type Localizer

type Localizer struct {
	Locales []string

	LocaleParamNames  []string
	LocaleCookieNames []string
	LocaleHeaderNames []string
}

Localizer localizer middleware

Example
router := xin.Default()

router.Use(NewLocalizer("en", "ja", "zh").Handle)
router.GET("/", func(c *xin.Context) {
	c.String(200, c.Locale)
})

server := &http.Server{
	Addr:    "127.0.0.1:8888",
	Handler: router,
}

go func() {
	server.ListenAndServe()
}()

time.Sleep(time.Millisecond * 100)

req, _ := http.NewRequest("GET", "http://127.0.0.1:8888/", nil)
req.Header.Add("Accept-Languages", "ja;zh")

client := &http.Client{Timeout: time.Second * 1}
res, _ := client.Do(req)

raw, _ := io.ReadAll(res.Body)
fmt.Println(string(raw))

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
server.Shutdown(ctx)

func NewLocalizer

func NewLocalizer(locales ...string) *Localizer

NewLocalizer create a default Localizer

func (*Localizer) Handle

func (ll *Localizer) Handle(c *xin.Context)

Handle process xin request

type OriginAccessController

type OriginAccessController struct {
	AllowOrigins     *hashset.HashSet[string]
	AllowCredentials bool
	AllowMethods     string
	AllowHeaders     string
	ExposeHeaders    string
	MaxAge           int
}

OriginAccessController Access-Control-Allow-Origin response header middleware see - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age if Origins contains the request header 'origin', set the Access-Control-Allow-Origin response header. if the request method is OPTIONS, also set the status code to 200.

func NewOriginAccessController

func NewOriginAccessController(origins ...string) *OriginAccessController

NewOriginAccessController create a default OriginAccessController

func (*OriginAccessController) Handle

func (ll *OriginAccessController) Handle(c *xin.Context)

Handle process xin request

func (*OriginAccessController) SetAllowCredentials

func (ll *OriginAccessController) SetAllowCredentials(allow bool)

SetAllowCredentials set allow Credentials

func (*OriginAccessController) SetAllowHeaders

func (ll *OriginAccessController) SetAllowHeaders(headers string)

SetAllowHeaders set allow headers

func (*OriginAccessController) SetAllowMethods

func (ll *OriginAccessController) SetAllowMethods(methods string)

SetAllowMethods set Access-Control-Allow-Methods

func (*OriginAccessController) SetAllowOrigins

func (ll *OriginAccessController) SetAllowOrigins(origins ...string)

SetAllowOrigins set allow origins

func (*OriginAccessController) SetExposeHeaders

func (ll *OriginAccessController) SetExposeHeaders(headers string)

SetExposeHeaders set expose headers

func (*OriginAccessController) SetMaxAge

func (ll *OriginAccessController) SetMaxAge(sec int)

SetMaxAge set Access-Control-Max-Age

type ProxiedFlag

type ProxiedFlag int

ProxiedFlag Proxied flag

const (
	ProxiedAny ProxiedFlag = 1 << iota
	ProxiedAuth
	ProxiedExpired
	ProxiedNoCache
	ProxiedNoStore
	ProxiedPrivate
	ProxiedNoLastModified
	ProxiedNoETag
	ProxiedOff = 0
)

Proxied option flags

func (ProxiedFlag) String

func (pf ProxiedFlag) String() string

String return level string

type RequestRateLimiter

type RequestRateLimiter struct {
	Limit           int
	TrustedClients  []*net.IPNet
	TooManyRequests func(c *xin.Context)
	// contains filtered or unexported fields
}

RequestRateLimiter http request limit middleware

func NewRequestRateLimiter

func NewRequestRateLimiter(limit int, duration, cleanupInterval time.Duration) *RequestRateLimiter

NewRequestRateLimiter create a default RequestRateLimiter middleware

func (*RequestRateLimiter) Duration

func (rrl *RequestRateLimiter) Duration() time.Duration

func (*RequestRateLimiter) Handle

func (rrl *RequestRateLimiter) Handle(c *xin.Context)

Handle process xin request

func (*RequestRateLimiter) SetDuration added in v1.2.4

func (rrl *RequestRateLimiter) SetDuration(d time.Duration)

func (*RequestRateLimiter) SetTrustedClients

func (rrl *RequestRateLimiter) SetTrustedClients(cidrs []string) error

type RequestSizeLimiter

type RequestSizeLimiter struct {
	DrainBody      bool // drain request body if we are under apache, otherwise the apache will return 502 Bad Gateway
	MaxBodySize    int64
	GetMaxBodySize func(c *xin.Context) int64
	BodyTooLarge   func(c *xin.Context)
}

RequestSizeLimiter http request limit middleware

func NewRequestSizeLimiter

func NewRequestSizeLimiter(maxBodySize int64) *RequestSizeLimiter

NewRequestSizeLimiter create a default RequestSizeLimiter middleware

func (*RequestSizeLimiter) Handle

func (rsl *RequestSizeLimiter) Handle(c *xin.Context)

Handle process xin request

type ResponseCompressor

type ResponseCompressor struct {
	Encodings map[string]CompressorProvider
	// contains filtered or unexported fields
}

ResponseCompressor Compresses responses using the “gzip” method

Example
router := xin.Default()

router.Use(DefaultResponseCompressor().Handle)
router.GET("/", func(c *xin.Context) {
	c.String(200, strings.Repeat("This is a Test!\n", 1000))
})

server := &http.Server{
	Addr:    "127.0.0.1:8888",
	Handler: router,
}

go func() {
	server.ListenAndServe()
}()

time.Sleep(time.Millisecond * 100)

req, _ := http.NewRequest("GET", "http://127.0.0.1:8888/", nil)
client := &http.Client{Timeout: time.Second * 1}
client.Do(req)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
server.Shutdown(ctx)

func DefaultResponseCompressor

func DefaultResponseCompressor() *ResponseCompressor

DefaultResponseCompressor create a default zipper = NewResponseCompressor(1024)

func NewResponseCompressor

func NewResponseCompressor(minLength int) *ResponseCompressor

NewResponseCompressor create a http response compressor proxied: ProxiedAny vary: true minLength: 1024

func (*ResponseCompressor) Disable

func (xrc *ResponseCompressor) Disable(disabled bool)

Disable disable the gzip compress or not

func (*ResponseCompressor) Handle

func (xrc *ResponseCompressor) Handle(ctx *xin.Context)

Handle process xin request

func (*ResponseCompressor) IgnorePathPrefix

func (xrc *ResponseCompressor) IgnorePathPrefix(ps ...string)

IgnorePathPrefix ignore URL path prefix

func (*ResponseCompressor) IgnorePathRegexp

func (xrc *ResponseCompressor) IgnorePathRegexp(ps ...string)

IgnorePathRegexp ignore URL path regexp

func (*ResponseCompressor) SetHTTPVersion

func (xrc *ResponseCompressor) SetHTTPVersion(major, minor int)

SetHTTPVersion Sets the minimum HTTP Proto version of a request required to compress a response.

func (*ResponseCompressor) SetMimeTypes

func (xrc *ResponseCompressor) SetMimeTypes(mts ...string)

SetMimeTypes Enables compressing of responses for the specified MIME types. The special value "*" matches any MIME type. Default:

text/html
text/plain
text/xml
text/css
text/javascript
text/json
text/comma-separated-values
text/tab-separated-values
application/xml
application/xhtml+xml
application/rss+xml
application/atom_xml
application/json
application/javascript
application/x-javascript

func (*ResponseCompressor) SetProxied

func (xrc *ResponseCompressor) SetProxied(ps ...string)

SetProxied Enables or disables compressing of responses for proxied requests depending on the request and response. The fact that the request is proxied is determined by the presence of the “Via” request header field. The directive accepts multiple parameters: off

disables compression for all proxied requests, ignoring other parameters;

any (Default)

enables compression for all proxied requests.

auth

enables compression if a request header includes the “Authorization” field;

expired

enables compression if a response header includes the “Expires” field with a value that disables caching;

no-cache

enables compression if a response header includes the “Cache-Control” field with the “no-cache” parameter;

no-store

enables compression if a response header includes the “Cache-Control” field with the “no-store” parameter;

private

enables compression if a response header includes the “Cache-Control” field with the “private” parameter;

no_last_modified

enables compression if a response header does not include the “Last-Modified” field;

no_etag

enables compression if a response header does not include the “ETag” field;

func (*ResponseCompressor) Vary

func (xrc *ResponseCompressor) Vary(vary bool)

Vary Enables or disables inserting the “Vary: Accept-Encoding” response header field. Default: true

type ResponseHeader

type ResponseHeader struct {
	Header map[string]string
}

ResponseHeader response header middleware

func NewResponseHeader

func NewResponseHeader(header map[string]string) *ResponseHeader

NewResponseHeader create a default ResponseHeader

func (*ResponseHeader) Handle

func (rh *ResponseHeader) Handle(c *xin.Context)

Handle process xin request

type TokenProtector

type TokenProtector struct {
	Cryptor        cpt.Cryptor // cryptor to encode/decode cookie, MUST concurrent safe
	Expires        time.Duration
	AttrKey        string
	ParamName      string
	HeaderName     string
	CookieName     string
	CookieMaxAge   time.Duration
	CookieDomain   string
	CookiePath     string
	CookieSecure   bool
	CookieHttpOnly bool
	CookieSameSite http.SameSite
	AbortStatus    int
	AbortFunc      func(*xin.Context)
	// contains filtered or unexported fields
}

TokenProtector token protector for CSRF

func NewTokenProtector

func NewTokenProtector(secret string) *TokenProtector

NewTokenProtector create a default TokenProtector default methods: DELETE, PATCH, POST, PUT

func (*TokenProtector) Handle

func (tp *TokenProtector) Handle(c *xin.Context)

Handle process xin request

func (*TokenProtector) RefreshToken

func (tp *TokenProtector) RefreshToken(c *xin.Context) string

func (*TokenProtector) SetMethods

func (tp *TokenProtector) SetMethods(ms ...string)

SetMethods Set the http methods to protect default methods: DELETE, PATCH, POST, PUT

func (*TokenProtector) SetSecret

func (tp *TokenProtector) SetSecret(secret string)

SetSecret Set the Cryptor secret

type ZlibCompressorProvider

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

func NewZlibCompressorProvider

func NewZlibCompressorProvider() *ZlibCompressorProvider

func (*ZlibCompressorProvider) GetCompressor

func (gcws *ZlibCompressorProvider) GetCompressor() Compressor

func (*ZlibCompressorProvider) NewCompressor

func (gcws *ZlibCompressorProvider) NewCompressor() any

func (*ZlibCompressorProvider) PutCompressor

func (gcws *ZlibCompressorProvider) PutCompressor(cw Compressor)

Jump to

Keyboard shortcuts

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