middleware

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlgorithmHS256 = "HS256"
)

Variables

View Source
var CSRFDefaultConfig = CSRFConfig{
	TokenLength:  16,
	TokenLookup:  "header:" + yee.HeaderXCSRFToken,
	Key:          "csrf",
	CookieName:   "_csrf",
	CookieMaxAge: 28800,
}
View Source
var DefaultGzipConfig = GzipConfig{Level: 1}
View Source
var DefaultJwtConfig = JwtConfig{
	GetKey:        "auth",
	SigningMethod: AlgorithmHS256,
	AuthScheme:    "Bearer",
	TokenLookup:   "header:" + yee.HeaderAuthorization,
	Claims:        jwt.MapClaims{},
}
View Source
var DefaultLoggerConfig = LoggerConfig{
	Format:   `"url":"${url}" "method":"${method}" "status":${status} "protocol":"${protocol}" "remote_ip":"${remote_ip}" "bytes_in": "${bytes_in} bytes" "bytes_out": "${bytes_out} bytes"`,
	Level:    3,
	IsLogger: true,
}
View Source
var DefaultRateLimit = RateLimitConfig{
	Time: 1 * time.Second,
	Rate: 5,
}
View Source
var DefaultRequestIDConfig = RequestIDConfig{
	// contains filtered or unexported fields
}
View Source
var DefaultSecureConfig = SecureConfig{
	XSSProtection:      "1; mode=block",
	ContentTypeNosniff: "nosniff",
	XFrameOptions:      "SAMEORIGIN",
	HSTSPreloadEnabled: false,
}

Functions

func BasicAuth added in v0.0.6

func BasicAuth(fn fnValidator) yee.HandlerFunc

func BasicAuthWithConfig added in v0.0.6

func BasicAuthWithConfig(config BasicAuthConfig) yee.HandlerFunc

func CSRFWithConfig added in v0.0.6

func CSRFWithConfig(config CSRFConfig) yee.HandlerFunc

func Cors

func Cors() yee.HandlerFunc

func CorsWithConfig

func CorsWithConfig(config CORSConfig) yee.HandlerFunc

func Csrf added in v0.0.6

func Csrf() yee.HandlerFunc

func Gzip

func Gzip() yee.HandlerFunc

func GzipWithConfig

func GzipWithConfig(config GzipConfig) yee.HandlerFunc

func JWTWithConfig

func JWTWithConfig(config JwtConfig) yee.HandlerFunc

func Logger

func Logger() yee.HandlerFunc

func LoggerWithConfig

func LoggerWithConfig(config LoggerConfig) yee.HandlerFunc

func RateLimit added in v0.0.6

func RateLimit() yee.HandlerFunc

func RateLimitWithConfig added in v0.0.6

func RateLimitWithConfig(config RateLimitConfig) yee.HandlerFunc

func Recovery

func Recovery() yee.HandlerFunc

Recovery is a recovery middleware when the program was panic it can recovery program and print stack info

func RequestID added in v0.0.6

func RequestID() yee.HandlerFunc

func RequestIDWithConfig added in v0.0.6

func RequestIDWithConfig(config RequestIDConfig) yee.HandlerFunc

func Secure

func Secure() yee.HandlerFunc

func SecureWithConfig

func SecureWithConfig(config SecureConfig) yee.HandlerFunc

Types

type BasicAuthConfig added in v0.0.6

type BasicAuthConfig struct {
	Validator fnValidator
	Realm     string
}

type CORSConfig

type CORSConfig struct {
	Origins          []string
	AllowMethods     []string
	AllowHeaders     []string
	AllowCredentials bool
	ExposeHeaders    []string
	MaxAge           int
}

type CSRFConfig added in v0.0.6

type CSRFConfig struct {
	TokenLength    uint8
	TokenLookup    string
	Key            string
	CookieName     string
	CookieDomain   string
	CookiePath     string
	CookieMaxAge   int
	CookieSecure   bool
	CookieHttpOnly bool
}

type GzipConfig

type GzipConfig struct {
	Level int
}

type JWTErrorHandler

type JWTErrorHandler func(error) error

type JWTSuccessHandler added in v0.0.8

type JWTSuccessHandler func(yee.Context)

JWTSuccessHandler defines a function which is executed for a valid token.

type JwtConfig

type JwtConfig struct {
	GetKey        string
	AuthScheme    string
	SigningKey    interface{}
	SigningMethod string
	TokenLookup   string
	Claims        jwt.Claims

	ErrorHandler   JWTErrorHandler
	SuccessHandler JWTSuccessHandler
	// contains filtered or unexported fields
}

type LoggerConfig

type LoggerConfig struct {
	Format   string
	Level    uint8
	IsLogger bool
}

type RateLimitConfig added in v0.0.6

type RateLimitConfig struct {
	Time time.Duration
	Rate int
	// contains filtered or unexported fields
}

type RequestIDConfig added in v0.0.6

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

type SecureConfig

type SecureConfig struct {
	XSSProtection string `yaml:"xss_protection"`

	ContentTypeNosniff string `yaml:"content_type_nosniff"`

	XFrameOptions string `yaml:"x_frame_options"`

	HSTSMaxAge int `yaml:"hsts_max_age"`

	HSTSExcludeSubdomains bool `yaml:"hsts_exclude_subdomains"`

	ContentSecurityPolicy string `yaml:"content_security_policy"`

	CSPReportOnly bool `yaml:"csp_report_only"`

	HSTSPreloadEnabled bool `yaml:"hsts_preload_enabled"`

	ReferrerPolicy string `yaml:"referrer_policy"`
}

Jump to

Keyboard shortcuts

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