Documentation ¶
Index ¶
- Variables
- func AlwaysSkip(*http.Request) bool
- func CSRF(c CSRFConfig) func(http.Handler) http.Handler
- func DefaultSkipper(*http.Request) bool
- func SkipHTTP(r *http.Request) bool
- func SkipHTTPS(r *http.Request) bool
- type CORSConfig
- type CSRFConfig
- type CompressConfig
- type Compressor
- type HSTSConfig
- type Middleware
- func AddHeader(key, value string) Middleware
- func CORS(config CORSConfig) Middleware
- func Chain(hs ...Middleware) Middleware
- func Compress(config CompressConfig) Middleware
- func HSTS(config HSTSConfig) Middleware
- func HSTSPreload() Middleware
- func NonWWWRedirect() Middleware
- func WWWRedirect() Middleware
- type Skipper
Constants ¶
This section is empty.
Variables ¶
View Source
var ( GzipCompressor = CompressConfig{ Skipper: DefaultSkipper, New: func() Compressor { g, err := gzip.NewWriterLevel(ioutil.Discard, gzip.DefaultCompression) if err != nil { panic(err) } return g }, Encoding: "gzip", Vary: defaultCompressVary, Types: defaultCompressTypes, MinLength: defaultCompressMinLength, } DeflateCompressor = CompressConfig{ Skipper: DefaultSkipper, New: func() Compressor { g, err := flate.NewWriter(ioutil.Discard, flate.DefaultCompression) if err != nil { panic(err) } return g }, Encoding: "deflate", Vary: defaultCompressVary, Types: defaultCompressTypes, MinLength: defaultCompressMinLength, } )
pre-defined compressors
View Source
var ( DefaultHSTS = HSTSConfig{ Skipper: SkipHTTP, MaxAge: 31536000 * time.Second, IncludeSubDomains: false, Preload: false, } PreloadHSTS = HSTSConfig{ Skipper: SkipHTTP, MaxAge: 63072000 * time.Second, IncludeSubDomains: true, Preload: true, } )
Pre-defiend config
View Source
var BrCompressor = CompressConfig{ Skipper: AlwaysSkip, }
BrCompressor is a noop compressor fallback for br
View Source
var DefaultCORS = CORSConfig{ AllowAllOrigins: true, AllowMethods: []string{ http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, }, AllowHeaders: []string{ "Content-Type", "Authorization", }, MaxAge: time.Hour, }
DefaultCORS is the default cors config for public api
Functions ¶
Types ¶
type CORSConfig ¶ added in v0.4.0
type CORSConfig struct { Skipper Skipper AllowAllOrigins bool AllowOrigins []string AllowMethods []string AllowHeaders []string AllowCredentials bool ExposeHeaders []string MaxAge time.Duration }
CORSConfig is the cors config
type CSRFConfig ¶ added in v0.4.0
type CSRFConfig struct { Origins []string ForbiddenHandler http.Handler IgnoreProto bool Force bool }
CSRFConfig is the csrf config
type CompressConfig ¶ added in v0.3.0
type CompressConfig struct { Skipper Skipper New func() Compressor Encoding string // http Accept-Encoding, Content-Encoding value Vary bool // add Vary: Accept-Encoding Types string // only compress for given types, * for all types MinLength int // skip if Content-Length less than given value }
CompressConfig is the compress middleware config
type Compressor ¶ added in v0.3.0
Compressor type
type HSTSConfig ¶ added in v0.3.0
HSTSConfig is the HSTS config
type Middleware ¶
Middleware is the http middleware
func AddHeader ¶ added in v0.4.0
func AddHeader(key, value string) Middleware
AddHeader creates new middleware that adds a header to response
func CORS ¶ added in v0.4.0
func CORS(config CORSConfig) Middleware
CORS creates new CORS middleware
func Chain ¶
func Chain(hs ...Middleware) Middleware
Chain is the helper function for chain middlewares into one middleware
func Compress ¶ added in v0.3.0
func Compress(config CompressConfig) Middleware
Compress creates new compress middleware
func HSTS ¶ added in v0.3.0
func HSTS(config HSTSConfig) Middleware
HSTS creates new HSTS middleware
func HSTSPreload ¶ added in v0.3.0
func HSTSPreload() Middleware
HSTSPreload is the short-hand for HSTS(PreloadHSTS)
func WWWRedirect ¶ added in v0.3.0
func WWWRedirect() Middleware
WWWRedirect redirects non-www to www
Click to show internal directories.
Click to hide internal directories.