middleware

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 14 Imported by: 4

Documentation

Overview

Package middleware recommended use: app.UseRouter cors configs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFromJWT

func GetFromJWT(ctx iris.Context) interface{}

GetFromJWT get raw claims info set from config When called this method will need JWTConfig initialed first, call NewJWT if necessary You can get token from the

func JWTSession

func JWTSession(ctx iris.Context)

func JWTUpdate added in v0.0.5

func JWTUpdate(ctx iris.Context, claims interface{})

JWTUpdate 必须要在初始化后调用

func NewCORS

func NewCORS(cfg *CorsConfig) iris.Handler

NewCORS POST、PUT、PATCH和DELETE 标准上要求浏览器在这些请求上都要加上 Origin Header CORS 安全策略主要应用于浏览器页面跨域访问的时候,对于非浏览器页面请求,业界通常不予以特殊拦截

func NewIrisMonitor

func NewIrisMonitor(cfg *MonitorConfig) iris.Handler

NewIrisMonitor creates a new Monitor if needed recommended usage is app.UseGlobal not the useRouter function for that attackers may attack on those 404 not found uris, which UseRouter function will count, causing the metrics too heavy

func NewJWT

func NewJWT(cfg *JWTConfig) iris.Handler

NewJWT return the JWT middleware for iris web framework This returned middleware can be used in the project only if you need to set Token only here, also you can use in any project if you want, just make sure the configuration is the same.

func NewMonitor

func NewMonitor(cfg *MonitorConfig) *monitor

func NewRequestLogger

func NewRequestLogger(cfg *RequestLogConfig) iris.Handler

Types

type CorsConfig

type CorsConfig struct {
	AllowOrigin []string `json:"allowOrigin" yaml:"allow-origin"`
	AllowHeader string   `json:"allowHeader" yaml:"allow-header"`
	MaxAge      string   `json:"maxAge" yaml:"max-age"`
}

func NewDefaultCorsCfg

func NewDefaultCorsCfg() *CorsConfig

NewDefaultCorsCfg 默认cors 配置

type JWTConfig

type JWTConfig struct {
	Name   string `json:"name" yaml:"name"`     // Name of the JWT
	Expire int    `json:"expire" yaml:"expire"` // JWT expire time
	Domain string `json:"domain" yaml:"domain"` // JWT domain
	Secret string `json:"key" yaml:"key"`       // Secret of the JWT

	Claims       func(ctx iris.Context) (interface{}, error) // set if the return value from NewJWT is used as middleware
	Deserializer func(data []byte) (interface{}, error)      // must be set
}

JWTConfig Json Web Token config

type MonitorConfig

type MonitorConfig struct {
	Port int      `json:"port" yaml:"port"`
	Path string   `json:"path" yaml:"path"`
	Tags []string `json:"tags" yaml:"tags"`
}

func NewDefaultMonitorCfg

func NewDefaultMonitorCfg() *MonitorConfig

type RequestLogConfig

type RequestLogConfig struct {
	WithLabels bool  `json:"withLabels" yaml:"with-labels"`
	LogLong    bool  `json:"logLong" yaml:"log-long"`
	Threshold  int64 `json:"threshold" yaml:"threshold"`
}

func DefaultLogConfig

func DefaultLogConfig() *RequestLogConfig

Jump to

Keyboard shortcuts

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