middleware

package
v0.0.0-...-aac5923 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlgorithmHS256 = "HS256"
)

Variables

View Source
var DefaultCORSConfig = CORSConfig{
	Origins:      []string{"*"},
	AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodPut, http.MethodPatch, http.MethodPost, http.MethodDelete},
}
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 DefaultSecureConfig = SecureConfig{
	XSSProtection:      "1; mode=block",
	ContentTypeNosniff: "nosniff",
	XFrameOptions:      "SAMEORIGIN",
	HSTSPreloadEnabled: false,
}

Functions

func Cors

func Cors() yee.HandlerFunc

func CorsWithConfig

func CorsWithConfig(config CORSConfig) 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 Recovery

func Recovery() yee.HandlerFunc

func Secure

func Secure() yee.HandlerFunc

func SecureWithConfig

func SecureWithConfig(config SecureConfig) yee.HandlerFunc

Types

type CORSConfig

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

type GzipConfig

type GzipConfig struct {
	Level int
}

type JWTErrorHandler

type JWTErrorHandler func(error) error

type JwtConfig

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

	ErrorHandler JWTErrorHandler
	// contains filtered or unexported fields
}

type LoggerConfig

type LoggerConfig struct {
	Format   string
	Level    uint8
	IsLogger bool
}

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