middleware

package
v0.0.0-...-455e706 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const UsernameKey = "username"

UsernameKey defines the key in gin context which represents the owner of the secret.

View Source
const (
	// XRequestIDKey defines X-Request-ID key string.
	XRequestIDKey = "X-Request-ID"
)

Variables

View Source
var Middlewares = defaultMiddlewares() //默认的中间件

Functions

func Context

func Context() gin.HandlerFunc

func Cors

func Cors() gin.HandlerFunc

跨域中间件 Cors add cors headers. 允许哪些内容能够访问

func GetDefaultLogFormatterWithRequestID

func GetDefaultLogFormatterWithRequestID() gin.LogFormatter

GetDefaultLogFormatterWithRequestID returns gin.LogFormatter with 'RequestID'.

func GetLoggerConfig

func GetLoggerConfig(formatter gin.LogFormatter, output io.Writer, skipPaths []string) gin.LoggerConfig

GetLoggerConfig return gin.LoggerConfig which will write the logs to specified io.Writer with given gin.LogFormatter. By default gin.DefaultWriter = os.Stdout reference: https://github.com/gin-gonic/gin#custom-log-format

func GetRequestIDFromContext

func GetRequestIDFromContext(c *gin.Context) string

GetRequestIDFromContext returns 'RequestID' from the given context if present.

func GetRequestIDFromHeaders

func GetRequestIDFromHeaders(c *gin.Context) string

GetRequestIDFromHeaders returns 'RequestID' from the headers if present.

func Logger

func Logger() gin.HandlerFunc

Logger instances a Logger middleware that will write the logs to gin.DefaultWriter. By default gin.DefaultWriter = os.Stdout.

func LoggerWithConfig

func LoggerWithConfig(conf gin.LoggerConfig) gin.HandlerFunc

LoggerWithConfig instance a Logger middleware with config.

func LoggerWithFormatter

func LoggerWithFormatter(f gin.LogFormatter) gin.HandlerFunc

LoggerWithFormatter instance a Logger middleware with the specified log format function.

func LoggerWithWriter

func LoggerWithWriter(out io.Writer, notlogged ...string) gin.HandlerFunc

LoggerWithWriter instance a Logger middleware with the specified writer buffer. Example: os.Stdout, a file opened in write mode, a socket...

func NoCache

func NoCache(c *gin.Context)

NoCache is a middleware function that appends headers to prevent the client from caching the HTTP response.

func Options

func Options(c *gin.Context)

Options is a middleware function that appends headers for options requests and aborts then exits the middleware chain and ends the request.

func PubMsg

func PubMsg() gin.HandlerFunc

构建往redis发送channel的中间件

func RequestID

func RequestID() gin.HandlerFunc

调用过程生成的 X-Request-ID 中间件 RequestID is a middleware that injects a 'X-Request-ID' into the context and request/response header of each request.

func Secure

func Secure(c *gin.Context)

Secure is a middleware function that appends security and resource access headers.

func Validation

func Validation() gin.HandlerFunc

权限验证中间件

Types

type AuthStrategy

type AuthStrategy interface {
	AuthFunc() gin.HandlerFunc
}

认证策略接口

type AuthStrategyUse

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

外部使用

func (*AuthStrategyUse) Get

func (au *AuthStrategyUse) Get() gin.HandlerFunc

使用策略函数

func (*AuthStrategyUse) SetStrategy

func (au *AuthStrategyUse) SetStrategy(as AuthStrategy)

设置策略接口

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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