middleware

package
v0.0.0-...-48fb7be Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Secret              = core.Cfg.JWT.SignKey                              //密码自行设定
	TokenExpireDuration = time.Duration(core.Cfg.JWT.Expires) * time.Minute //设置过期时间

	TokenLookup   = "header: Authorization, query: token, cookie: jwt"
	TokenHeadName = "Bearer"

	// ErrEmptyAuthHeader can be thrown if authing with a HTTP header, the Decrypt header needs to be set
	ErrEmptyAuthHeader = errors.New("auth header is empty")

	// ErrInvalidAuthHeader indicates auth header is invalid, could for example have the wrong Realm name
	ErrInvalidAuthHeader = errors.New("auth header is invalid")

	// ErrEmptyQueryToken can be thrown if authing with URL Query, the query token variable is empty
	ErrEmptyQueryToken = errors.New("query token is empty")

	// ErrEmptyCookieToken can be thrown if authing with a cookie, the token cokie is empty
	ErrEmptyCookieToken = errors.New("cookie token is empty")

	// ErrEmptyParamToken can be thrown if authing with parameter in path, the parameter in path is empty
	ErrEmptyParamToken = errors.New("parameter token is empty")
)

Functions

func AccessLimit

func AccessLimit() gin.HandlerFunc

func AppKey

func AppKey(c *gin.Context)

func CorsByRules

func CorsByRules(corsCfg *config.CORS) gin.HandlerFunc

CorsByRules 按照配置处理跨域请求

func CustomError

func CustomError(c *gin.Context)

func Fail

func Fail(c *gin.Context, code int, msg string, data ...any)

func GenToken

func GenToken(userId, companyId string, timeout time.Time, secret string) (string, error)

func InitMiddleware

func InitMiddleware(r *gin.Engine, cfg *config.AppCfg)

func JWTAuthMiddleware

func JWTAuthMiddleware() func(c *gin.Context)

func LoggerToFile

func LoggerToFile() gin.HandlerFunc

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 ParseToken

func ParseToken(tokenString string, secret string) (jwt.StandardClaims, error)

func ReqId

func ReqId(c *gin.Context)

获取请求id,没有默认一个

func ValidUserId

func ValidUserId() func(*gin.Context)

func WhileIp

func WhileIp() gin.HandlerFunc

白名单 权限检查中间件

Types

type Access

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

type CustomResponseWriter

type CustomResponseWriter struct {
	gin.ResponseWriter
	// contains filtered or unexported fields
}

func NewCustomResponseWriter

func NewCustomResponseWriter(responseWriter gin.ResponseWriter) *CustomResponseWriter

func (CustomResponseWriter) Write

func (w CustomResponseWriter) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

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