middleware

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CSRFDefaultConfig = CSRFConfig{
	TokenLength:  16,
	TokenLookup:  "header:" + yee.HeaderXCSRFToken,
	Key:          "csrf",
	CookieName:   "_csrf",
	CookieMaxAge: 28800,
}

CSRFDefaultConfig is the default config of CSRF middleware

DefaultCORSConfig is the default config of CORS middleware

View Source
var DefaultGzipConfig = GzipConfig{Level: 1}

DefaultGzipConfig is the default config of gzip middleware

View Source
var DefaultJwtConfig = JwtConfig{
	GetKey:        "auth",
	SigningMethod: algorithmHS256,
	AuthScheme:    "Bearer",
	TokenLookup:   "header:" + yee.HeaderAuthorization,
	Claims:        jwt.MapClaims{},
}

DefaultJwtConfig is the default config of JWT middleware

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,
}

DefaultLoggerConfig is default config of logger middleware

View Source
var DefaultRateLimit = RateLimitConfig{
	Time: 1 * time.Second,
	Rate: 5,
}

DefaultRateLimit is the default config of rateLimit middleware

View Source
var DefaultRequestIDConfig = RequestIDConfig{
	// contains filtered or unexported fields
}

DefaultRequestIDConfig is the default config of requestID middleware

View Source
var DefaultSecureConfig = SecureConfig{
	XSSProtection:      "1; mode=block",
	ContentTypeNosniff: "nosniff",
	XFrameOptions:      "SAMEORIGIN",
	HSTSPreloadEnabled: false,
}

DefaultSecureConfig is default config of secure middleware

Functions

func BasicAuth

func BasicAuth(fn fnValidator) yee.HandlerFunc

BasicAuth is the default implementation BasicAuth middleware

func BasicAuthWithConfig

func BasicAuthWithConfig(config BasicAuthConfig) yee.HandlerFunc

BasicAuthWithConfig is the custom implementation BasicAuth middleware

func CSRF

func CSRF() yee.HandlerFunc

CSRF is the default implementation CSRF middleware

func CSRFWithConfig

func CSRFWithConfig(config CSRFConfig) yee.HandlerFunc

CSRFWithConfig is the custom implementation CSRF middleware

func Cors

func Cors() yee.HandlerFunc

Cors is the default implementation CORS middleware

func CorsWithConfig

func CorsWithConfig(config CORSConfig) yee.HandlerFunc

CorsWithConfig is the default implementation CORS middleware

func Gzip

func Gzip() yee.HandlerFunc

Gzip is the default implementation of gzip middleware

func GzipWithConfig

func GzipWithConfig(config GzipConfig) yee.HandlerFunc

GzipWithConfig is the custom implementation of gzip middleware

func JWTWithConfig

func JWTWithConfig(config JwtConfig) yee.HandlerFunc

JWTWithConfig is the custom implementation CORS middleware

func Logger

func Logger() yee.HandlerFunc

Logger is default implementation of logger middleware

func LoggerWithConfig

func LoggerWithConfig(config LoggerConfig) yee.HandlerFunc

LoggerWithConfig is custom implementation of logger middleware

func RateLimit

func RateLimit() yee.HandlerFunc

RateLimit is the default implementation of rateLimit middleware

func RateLimitWithConfig

func RateLimitWithConfig(config RateLimitConfig) yee.HandlerFunc

RateLimitWithConfig is the custom implementation of rateLimit middleware

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

func RequestID() yee.HandlerFunc

RequestID is the default implementation of requestID middleware

func RequestIDWithConfig

func RequestIDWithConfig(config RequestIDConfig) yee.HandlerFunc

RequestIDWithConfig is the custom implementation of requestID middleware

func Secure

func Secure() yee.HandlerFunc

Secure is default implementation of secure middleware

func SecureWithConfig

func SecureWithConfig(config SecureConfig) yee.HandlerFunc

SecureWithConfig is custom implementation of secure middleware

Types

type BasicAuthConfig

type BasicAuthConfig struct {
	Validator fnValidator
	Realm     string
}

BasicAuthConfig defines the config of basicAuth middleware

type CORSConfig

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

CORSConfig defined the config of CORS middleware

type CSRFConfig

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

CSRFConfig defines the config of CSRF middleware

type GzipConfig

type GzipConfig struct {
	Level int
}

GzipConfig defines config of Gzip middleware

type JWTErrorHandler

type JWTErrorHandler func(error) error

JWTErrorHandler defines a function which is error for a valid token.

type JWTSuccessHandler

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
}

JwtConfig defines the config of JWT middleware

type LoggerConfig

type LoggerConfig struct {
	Format   string
	Level    uint8
	IsLogger bool
}

LoggerConfig defines config of logger middleware

type RateLimitConfig

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

RateLimitConfig defines config of rateLimit middleware

type RequestIDConfig

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

RequestIDConfig defines config of requestID middleware

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"`
}

SecureConfig defines config of secure middleware

Jump to

Keyboard shortcuts

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