middleware

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultAllowHeaders = []string{
	"Authorization",
	"Content-Length",
	"X-CSRF-Token",
	"Token",
	"Session",
	"Accept",
	"Origin",
	"Host",
	"Connection",
	"Accept-Encoding",
	"Accept-Language",
	"DNT",
	"Keep-Alive",
	"User-Agent",
	"X-Requested-With",
	"If-Modified-Since",
	"Cache-Control",
	"Content-Type",
}
View Source
var DefaultExposeHeaders = []string{
	"Content-Length",
	"Access-Control-Allow-Origin",
	"Access-Control-Allow-Headers",
	"Cache-Control",
	"Content-Language",
	"Content-Type",
	"Expires",
	"Last-Modified",
}

Functions

func AccessLog

func AccessLog(skipPaths []string, utc bool, timeFormat string) gin.HandlerFunc

AccessLog 使用ZAP接管GIN相关日志 timeFormat 时间格式 utc 是否使用UTC时间 skipPath 不记录日志的url.

func Cors

func Cors(args ...CorsOpt) gin.HandlerFunc

func RecoveryWithZap

func RecoveryWithZap() gin.HandlerFunc

RecoveryWithZap returns a gin.HandlerFunc (middleware) that recovers from any panics and logs requests using uber-go/zap. All errors are logged using zap.Error(). stack means whether output the stack info. The stack info is easy to find where the error occurs but the stack info is too large.

func UseMiddlewares

func UseMiddlewares(engine *gin.Engine, middlewares ...gin.HandlerFunc)

Types

type CorsConfig

type CorsConfig struct {
	AllowOrigins []string //允许哪些源 源: 协议+域名+端口 -> http://example.com

	AllowMethods []string //允许哪些请求方式

	AllowHeaders []string //允许哪些请求头

	AllowCredentials bool //是否允许传输Cookie

	ExposeHeaders []string //请求方可以拿到哪些请求头

	MaxAge time.Duration //本次预检请求的有效期

	AllowWildcard bool
}

type CorsOpt

type CorsOpt func(config *CorsConfig)

func CookieOpt

func CookieOpt(allow bool) CorsOpt

func ExHeaderOpt

func ExHeaderOpt(header ...string) CorsOpt

func HeaderOpt

func HeaderOpt(headers ...string) CorsOpt

func MaxAgeOpt

func MaxAgeOpt(maxAge time.Duration) CorsOpt

func MethodOpt

func MethodOpt(methods ...string) CorsOpt

func OriginOpt

func OriginOpt(origins ...string) CorsOpt

Jump to

Keyboard shortcuts

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