middleware

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 30 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 added in v0.0.6

func BasicAuth(fn fnValidator) yee.HandlerFunc

BasicAuth is the default implementation BasicAuth middleware

func BasicAuthWithConfig added in v0.0.6

func BasicAuthWithConfig(config BasicAuthConfig) yee.HandlerFunc

BasicAuthWithConfig is the custom implementation BasicAuth middleware

func CSRF added in v0.1.2

func CSRF() yee.HandlerFunc

CSRF is the default implementation CSRF middleware

func CSRFWithConfig added in v0.0.6

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 New added in v0.3.4

func New(e *yee.Core) io.Closer

func ProxyWithConfig added in v0.3.7

func ProxyWithConfig(config ProxyConfig) yee.HandlerFunc

func RateLimit added in v0.0.6

func RateLimit() yee.HandlerFunc

RateLimit is the default implementation of rateLimit middleware

func RateLimitWithConfig added in v0.0.6

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 added in v0.0.6

func RequestID() yee.HandlerFunc

RequestID is the default implementation of requestID middleware

func RequestIDWithConfig added in v0.0.6

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

func TraceWithConfig added in v0.3.4

func TraceWithConfig(config TraceConfig) yee.HandlerFunc

Types

type BasicAuthConfig added in v0.0.6

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

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

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 ProxyConfig added in v0.3.7

type ProxyConfig struct {
	BalanceType    string
	Transport      http.RoundTripper
	ModifyResponse func(*http.Response) error
	ProxyTarget    ProxyTargetHandler
}

type ProxyTarget added in v0.3.7

type ProxyTarget struct {
	Name string
	URL  *url.URL
}

type ProxyTargetHandler added in v0.3.7

type ProxyTargetHandler interface {
	MatchAlgorithm() ProxyTarget
}

type RateLimitConfig added in v0.0.6

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

RateLimitConfig defines config of rateLimit middleware

type RequestIDConfig added in v0.0.6

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

type TraceConfig added in v0.3.4

type TraceConfig struct {
	// OpenTracing Tracer instance which should be got before
	Tracer        opentracing.Tracer
	ComponentName string
	IsBodyDump    bool
	LimitHTTPBody bool
	LimitSize     int
}

Jump to

Keyboard shortcuts

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