Documentation
¶
Index ¶
- Constants
- type AccessLogCtx
- type AccessLogJSONWriter
- type AccessLogMultiWriter
- type AccessLogTextWriter
- type AccessLogWriter
- type AccessLogger
- type AuthUser
- type BasicAuth
- type CookieAuth
- func (ca *CookieAuth) Authorized(c *xin.Context)
- func (ca *CookieAuth) DeleteCookie(c *xin.Context)
- func (ca *CookieAuth) GetUserPassFromCookie(c *xin.Context) (username, password string, ok bool)
- func (ca *CookieAuth) Handle(c *xin.Context)
- func (ca *CookieAuth) Handler() xin.HandlerFunc
- func (ca *CookieAuth) SaveUserPassToCookie(c *xin.Context, username, password string) error
- func (ca *CookieAuth) Unauthorized(c *xin.Context)
- type DigestAuth
- type FindUserFunc
- type HTTPDumper
- type HTTPSRedirector
- type Localizer
- type OriginAccessController
- func (ll *OriginAccessController) Handle(c *xin.Context)
- func (ll *OriginAccessController) Handler() xin.HandlerFunc
- func (ll *OriginAccessController) SetAllowCredentials(allow bool)
- func (ll *OriginAccessController) SetAllowHeaders(headers string)
- func (ll *OriginAccessController) SetAllowMethods(methods string)
- func (ll *OriginAccessController) SetAllowOrigins(origins ...string)
- func (ll *OriginAccessController) SetExposeHeaders(headers string)
- func (ll *OriginAccessController) SetMaxAge(sec int)
- type ProxiedFlag
- type RequestLimiter
- type ResponseCompressor
- func (rc *ResponseCompressor) Disable(disabled bool)
- func (rc *ResponseCompressor) Handle(ctx *xin.Context)
- func (rc *ResponseCompressor) Handler() xin.HandlerFunc
- func (rc *ResponseCompressor) IgnorePathPrefix(ps ...string)
- func (rc *ResponseCompressor) IgnorePathRegexp(ps ...string)
- func (rc *ResponseCompressor) SetHTTPVersion(major, minor int)
- func (rc *ResponseCompressor) SetMimeTypes(mts ...string)
- func (rc *ResponseCompressor) SetProxied(ps ...string)
- func (rc *ResponseCompressor) Vary(vary bool)
- type ResponseHeader
- type TokenProtector
Examples ¶
Constants ¶
const ( AuthCookieName = "X_AUTH" AuthRedirectOriginURLQuery = "origin" )
const ( // LocaleParamName default parameter key name LocaleParamName = "_locale_" // LocaleHeaderName default http header name LocaleHeaderName = "X-Accept-Language" // LocaleCookieName default cookie name LocaleCookieName = "X_LOCALE" )
const ( BestCompression = flate.BestCompression BestSpeed = flate.BestSpeed DefaultCompression = flate.DefaultCompression NoCompression = flate.NoCompression )
const ( TokenAttrKey = "X_TOKEN" TokenParamName = "_token_" TokenHeaderName = "X-CSRF-TOKEN" //nolint: gosec TokenCookieName = "X_TOKEN" )
const AccessLogJSONFormat = `` /* 177-byte string literal not displayed */
AccessLogJSONFormat default json log format
const AccessLogTextFormat = "text:%t\t%S\t%T\t%B\t%c\t%r\t%m\t%h\t%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)
const AccessLogTimeFormat = "2006-01-02T15:04:05.000"
AccessLogTimeFormat default log time format
const AuthUserKey = "X_AUTH_USER"
AuthUserKey is the key for user credential authenticated saved in context
const HTTPDumpKey = "X_DUMP"
HTTPDumpKey is the key for dump http saved in context
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessLogCtx ¶ added in v1.0.12
type AccessLogJSONWriter ¶ added in v1.0.12
type AccessLogJSONWriter struct {
// contains filtered or unexported fields
}
AccessLogJSONWriter format(json-style) and write access log
func NewAccessLogJSONWriter ¶ added in v1.0.12
func NewAccessLogJSONWriter(writer io.Writer, format string) *AccessLogJSONWriter
NewAccessLogJSONWriter create json style writer for AccessLogger
func (*AccessLogJSONWriter) SetFormat ¶ added in v1.0.12
func (aljw *AccessLogJSONWriter) SetFormat(format string)
SetFormat set the access alw format
func (*AccessLogJSONWriter) SetOutput ¶ added in v1.0.12
func (aljw *AccessLogJSONWriter) SetOutput(w io.Writer)
SetOutput set the access log writer
func (*AccessLogJSONWriter) Write ¶ added in v1.0.12
func (aljw *AccessLogJSONWriter) Write(alc *AccessLogCtx)
Write write the access log
type AccessLogMultiWriter ¶ added in v1.0.12
type AccessLogMultiWriter struct {
Writers []AccessLogWriter
}
AccessLogMultiWriter write log to multiple writers.
func NewAccessLogMultiWriter ¶ added in v1.0.12
func NewAccessLogMultiWriter(ws ...AccessLogWriter) *AccessLogMultiWriter
NewAccessLogMultiWriter create a multi writer
func (*AccessLogMultiWriter) Write ¶ added in v1.0.12
func (mw *AccessLogMultiWriter) Write(alc *AccessLogCtx)
Write write the access log to multiple writers.
type AccessLogTextWriter ¶ added in v1.0.12
type AccessLogTextWriter struct {
// contains filtered or unexported fields
}
AccessLogTextWriter format(text) and write access log
func NewAccessLogTextWriter ¶ added in v1.0.12
func NewAccessLogTextWriter(writer io.Writer, format string) *AccessLogTextWriter
NewAccessLogTextWriter create text style writer for AccessLogger
func (*AccessLogTextWriter) SetFormat ¶ added in v1.0.12
func (altw *AccessLogTextWriter) SetFormat(format string)
SetFormat set the access alw format
func (*AccessLogTextWriter) SetOutput ¶ added in v1.0.12
func (altw *AccessLogTextWriter) SetOutput(w io.Writer)
SetOutput set the access log writer
func (*AccessLogTextWriter) Write ¶ added in v1.0.12
func (altw *AccessLogTextWriter) Write(alc *AccessLogCtx)
Write write the access log
type AccessLogWriter ¶ added in v1.0.12
type AccessLogWriter interface {
Write(*AccessLogCtx)
}
AccessLogWriter access log writer for XIN
%t{format} - Request start time, if {format} is omitted, '2006-01-02T15:04:05.000' is used. %c - Client IP ([X-Forwarded-For, X-Real-Ip] or RemoteIP()) %r - Remote IP:Port (%a) %u - Request URL %p - Request protocol %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 %T - Time taken to process the request, in milliseconds %S - HTTP status code of the response %B - Response body length (%L) %H - Local hostname %H{name} - Response header %n: EOL(Windows: "\r\n", Other: "\n")
func NewAccessLogWriter ¶ added in v1.0.12
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)).Handler()) 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)
Output:
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 ¶ added in v1.0.10
func (al *AccessLogger) Handle(c *xin.Context)
Handle process xin request
func (*AccessLogger) Handler ¶
func (al *AccessLogger) Handler() xin.HandlerFunc
Handler returns the HandlerFunc
func (*AccessLogger) SetWriter ¶ added in v1.0.12
func (al *AccessLogger) SetWriter(alw AccessLogWriter)
SetWriter set the access logger writer
type BasicAuth ¶
type BasicAuth struct { Realm string FindUser FindUserFunc AuthUserKey string AuthPassed xin.HandlerFunc AuthFailed xin.HandlerFunc AuthRequired xin.HandlerFunc }
BasicAuth basic http authenticator
func NewBasicAuth ¶
func NewBasicAuth(f FindUserFunc) *BasicAuth
func (*BasicAuth) Authorized ¶ added in v1.0.15
Authorized just call c.Next()
func (*BasicAuth) Handler ¶
func (ba *BasicAuth) Handler() xin.HandlerFunc
Handler returns the xin.HandlerFunc
func (*BasicAuth) Unauthorized ¶ added in v1.0.15
Unauthorized set basic authentication WWW-Authenticate header
type CookieAuth ¶ added in v1.0.14
type CookieAuth struct { Cryptor cpt.Cryptor FindUser FindUserFunc CookieName string CookieMaxAge time.Duration CookieDomain string CookiePath string CookieSecure bool CookieHttpOnly bool CookieSameSite http.SameSite AuthUserKey string RedirectURL string OriginURLQuery string AuthPassed xin.HandlerFunc AuthFailed xin.HandlerFunc AuthRequired xin.HandlerFunc }
CookieAuth cookie authenticator
func NewCookieAuth ¶ added in v1.0.14
func NewCookieAuth(f FindUserFunc, secret string) *CookieAuth
func (*CookieAuth) Authorized ¶ added in v1.0.15
func (ca *CookieAuth) Authorized(c *xin.Context)
Authorized just call c.Next()
func (*CookieAuth) DeleteCookie ¶ added in v1.0.14
func (ca *CookieAuth) DeleteCookie(c *xin.Context)
func (*CookieAuth) GetUserPassFromCookie ¶ added in v1.0.14
func (ca *CookieAuth) GetUserPassFromCookie(c *xin.Context) (username, password string, ok bool)
func (*CookieAuth) Handle ¶ added in v1.0.14
func (ca *CookieAuth) Handle(c *xin.Context)
Handle process xin request
func (*CookieAuth) Handler ¶ added in v1.0.14
func (ca *CookieAuth) Handler() xin.HandlerFunc
Handler returns the xin.HandlerFunc
func (*CookieAuth) SaveUserPassToCookie ¶ added in v1.0.14
func (ca *CookieAuth) SaveUserPassToCookie(c *xin.Context, username, password string) error
func (*CookieAuth) Unauthorized ¶ added in v1.0.15
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 xin.HandlerFunc AuthFailed xin.HandlerFunc AuthRequired xin.HandlerFunc // contains filtered or unexported fields }
DigestAuth digest http authenticator
func NewDigestAuth ¶
func NewDigestAuth(f FindUserFunc) *DigestAuth
func (*DigestAuth) Authorized ¶ added in v1.0.15
func (da *DigestAuth) Authorized(c *xin.Context)
Authorized just call c.Next()
func (*DigestAuth) Handle ¶ added in v1.0.10
func (da *DigestAuth) Handle(c *xin.Context)
Handle process xin request
func (*DigestAuth) Handler ¶
func (da *DigestAuth) Handler() xin.HandlerFunc
Handler returns the xin.HandlerFunc
func (*DigestAuth) Unauthorized ¶ added in v1.0.15
func (da *DigestAuth) Unauthorized(c *xin.Context)
Unauthorized set WWW-Authenticate header
type FindUserFunc ¶ added in v1.0.14
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).Handler()) 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)
Output:
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 ¶ added in v1.0.10
func (hd *HTTPDumper) Handle(c *xin.Context)
Handle process xin request
func (*HTTPDumper) Handler ¶
func (hd *HTTPDumper) Handler() xin.HandlerFunc
Handler returns the xin.HandlerFunc
type HTTPSRedirector ¶ added in v1.0.14
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 ¶ added in v1.0.14
func NewHTTPSRedirector() *HTTPSRedirector
func (*HTTPSRedirector) Disable ¶ added in v1.0.14
func (sh *HTTPSRedirector) Disable(disabled bool)
Disable disable the secure handler or not
func (*HTTPSRedirector) Handle ¶ added in v1.0.14
func (sh *HTTPSRedirector) Handle(c *xin.Context)
Handle process xin request
func (*HTTPSRedirector) Handler ¶ added in v1.0.14
func (sh *HTTPSRedirector) Handler() xin.HandlerFunc
Handler returns the xin.HandlerFunc
type Localizer ¶
type Localizer struct { Locales []string LocaleParamName string LocaleHeaderName string LocaleCookieName string FromAcceptLanguage bool }
Localizer localizer middleware
Example ¶
router := xin.Default() router.Use(NewLocalizer("en", "ja", "zh").Handler()) 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)
Output:
func NewLocalizer ¶
NewLocalizer create a default Localizer
func (*Localizer) Handler ¶
func (ll *Localizer) Handler() xin.HandlerFunc
Handler returns the xin.HandlerFunc
type OriginAccessController ¶ added in v1.0.12
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 ¶ added in v1.0.12
func NewOriginAccessController(origins ...string) *OriginAccessController
NewOriginAccessController create a default OriginAccessController
func (*OriginAccessController) Handle ¶ added in v1.0.12
func (ll *OriginAccessController) Handle(c *xin.Context)
Handle process xin request
func (*OriginAccessController) Handler ¶ added in v1.0.12
func (ll *OriginAccessController) Handler() xin.HandlerFunc
Handler returns the xin.HandlerFunc
func (*OriginAccessController) SetAllowCredentials ¶ added in v1.0.15
func (ll *OriginAccessController) SetAllowCredentials(allow bool)
SetAllowCredentials set allow Credentials
func (*OriginAccessController) SetAllowHeaders ¶ added in v1.0.15
func (ll *OriginAccessController) SetAllowHeaders(headers string)
SetAllowHeaders set allow headers
func (*OriginAccessController) SetAllowMethods ¶ added in v1.0.15
func (ll *OriginAccessController) SetAllowMethods(methods string)
SetAllowMethods set Access-Control-Allow-Methods
func (*OriginAccessController) SetAllowOrigins ¶ added in v1.0.15
func (ll *OriginAccessController) SetAllowOrigins(origins ...string)
SetAllowOrigins set allow origins
func (*OriginAccessController) SetExposeHeaders ¶ added in v1.0.15
func (ll *OriginAccessController) SetExposeHeaders(headers string)
SetExposeHeaders set expose headers
func (*OriginAccessController) SetMaxAge ¶ added in v1.0.15
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
type RequestLimiter ¶
type RequestLimiter struct { MaxBodySize int64 DrainBody bool // drain request body if we are under apache, otherwise the apache will return 502 Bad Gateway BodyTooLarge func(c *xin.Context, maxBodySize int64) }
RequestLimiter http request limit middleware
func NewRequestLimiter ¶
func NewRequestLimiter(maxBodySize int64, bodyTooLarge ...func(c *xin.Context, maxBodySize int64)) *RequestLimiter
NewRequestLimiter create a default RequestLimiter middleware
func (*RequestLimiter) Handle ¶ added in v1.0.10
func (rl *RequestLimiter) Handle(c *xin.Context)
Handle process xin request
func (*RequestLimiter) Handler ¶
func (rl *RequestLimiter) Handler() xin.HandlerFunc
Handler returns the xin.HandlerFunc
type ResponseCompressor ¶ added in v1.0.22
type ResponseCompressor struct {
// contains filtered or unexported fields
}
ResponseCompressor Compresses responses using the “gzip” method
Example ¶
router := xin.Default() router.Use(DefaultResponseCompressor().Handler()) 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)
Output:
func DefaultResponseCompressor ¶ added in v1.0.22
func DefaultResponseCompressor() *ResponseCompressor
DefaultResponseCompressor create a default zipper = NewResponseCompressor(DefaultCompression, 1024)
func NewResponseCompressor ¶ added in v1.0.22
func NewResponseCompressor(compressLevel, minLength int) *ResponseCompressor
NewResponseCompressor create a http response compressor proxied: ProxiedAny vary: true minLength: 1024
func (*ResponseCompressor) Disable ¶ added in v1.0.22
func (rc *ResponseCompressor) Disable(disabled bool)
Disable disable the gzip compress or not
func (*ResponseCompressor) Handle ¶ added in v1.0.22
func (rc *ResponseCompressor) Handle(ctx *xin.Context)
Handle process xin request
func (*ResponseCompressor) Handler ¶ added in v1.0.22
func (rc *ResponseCompressor) Handler() xin.HandlerFunc
Handler returns the xin.HandlerFunc
func (*ResponseCompressor) IgnorePathPrefix ¶ added in v1.0.22
func (rc *ResponseCompressor) IgnorePathPrefix(ps ...string)
IgnorePathPrefix ignore URL path prefix
func (*ResponseCompressor) IgnorePathRegexp ¶ added in v1.0.22
func (rc *ResponseCompressor) IgnorePathRegexp(ps ...string)
IgnorePathRegexp ignore URL path regexp
func (*ResponseCompressor) SetHTTPVersion ¶ added in v1.0.22
func (rc *ResponseCompressor) SetHTTPVersion(major, minor int)
SetHTTPVersion Sets the minimum HTTP Proto version of a request required to compress a response.
func (*ResponseCompressor) SetMimeTypes ¶ added in v1.0.22
func (rc *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 ¶ added in v1.0.22
func (rc *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 ¶ added in v1.0.22
func (rc *ResponseCompressor) Vary(vary bool)
Vary Enables or disables inserting the “Vary: Accept-Encoding” response header field. Default: true
type ResponseHeader ¶
ResponseHeader response header middleware
func NewResponseHeader ¶
func NewResponseHeader(header map[string]string) *ResponseHeader
NewResponseHeader create a default ResponseHeader
func (*ResponseHeader) Handle ¶ added in v1.0.10
func (rh *ResponseHeader) Handle(c *xin.Context)
Handle process xin request
func (*ResponseHeader) Handler ¶
func (rh *ResponseHeader) Handler() xin.HandlerFunc
Handler returns the xin.HandlerFunc
type TokenProtector ¶
type TokenProtector struct { Cryptor cpt.Cryptor 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 ¶ added in v1.0.10
func (tp *TokenProtector) Handle(c *xin.Context)
Handle process xin request
func (*TokenProtector) Handler ¶
func (tp *TokenProtector) Handler() xin.HandlerFunc
Handler returns the xin.HandlerFunc
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 ¶ added in v1.0.12
func (tp *TokenProtector) SetSecret(secret string)
SetSecret Set the Cryptor secret