middlewares

package
v0.0.0-...-a5c2be1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthKeyAccount  = "account"
	AuthKeyUserId   = "userId"
	AuthKeyUserRole = "userRole"
)
View Source
const (
	UserRoleGuest      = 0
	UserRoleUser       = 1
	UserRoleAdmin      = 8 // 普通管理员
	UserRoleSuperAdmin = 9 // 网站管理员
)

Variables

View Source
var (
	SigningKey = []byte("OM_SIGNING_KEY")
)
View Source
var WhiteUserIds = map[int]bool{
	4: true,
}

Functions

func AccessMiddleware

func AccessMiddleware() gin.HandlerFunc

func GenToken

func GenToken(userId int, account string, role string) (string, int64)

func RoleAdminMiddleware

func RoleAdminMiddleware(c *gin.Context)

func RoleUserMiddleware

func RoleUserMiddleware(c *gin.Context)

func SkipHandler

func SkipHandler(c *gin.Context, skippers ...SkipperFunc) bool

SkipHandler 统一处理跳过函数

Types

type CustomClaims

type CustomClaims struct {
	Account  string `json:"account"`
	UserId   int    `json:"user_id"`
	UserRole string `json:"user_role"`
	ExpireAt int64  `json:"expire_at"`
}

func (*CustomClaims) Valid

func (c *CustomClaims) Valid() error

type LogResponseWriter

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

func (*LogResponseWriter) Write

func (r *LogResponseWriter) Write(p []byte) (int, error)

type Middleware

type Middleware struct {
	Skippers   []SkipperFunc
	CasbinRule *casbin.Enforcer
}

func (Middleware) AuthMiddleware

func (m Middleware) AuthMiddleware(c *gin.Context)

func (Middleware) CasbinMiddleware

func (m Middleware) CasbinMiddleware(c *gin.Context)

CasbinMiddleware casbin中间件

type SkipperFunc

type SkipperFunc func(*gin.Context) bool

SkipperFunc 定义中间件跳过函数

func AllowPathPrefixSkipper

func AllowPathPrefixSkipper(prefixes ...string) SkipperFunc

AllowPathPrefixSkipper 检查请求路径是否包含指定的前缀,如果包含则跳过

Jump to

Keyboard shortcuts

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