middleware

package
v0.0.0-...-11946d1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const TokenRedisKeyPrefix = "LoginToke:"

Variables

View Source
var (
	TokenExpired     = errors.New("过期Token")
	TokenNotValidYet = errors.New("未生效Token")
	TokenMalformed   = errors.New("无效Token")
	TokenInvalid     = errors.New("非法Token")
)

Functions

func CasbinHandler

func CasbinHandler() gin.HandlerFunc

CasbinHandler

@Description: API访问权限Casbin鉴权
@return gin.HandlerFunc

func CompareRedisToken

func CompareRedisToken(userInfo UserInfo, tokenStr string) bool

CompareRedisToken 当前Token与Redis记录Token匹配

func Cors

func Cors() gin.HandlerFunc

Cors

@Description: 处理跨域请求
@return gin.HandlerFunc

func CreateToken

func CreateToken(userInfo UserInfo) (string, error)

CreateToken 根据用户信息生成Token

func GetTokenRedisKey

func GetTokenRedisKey(userId int64, userName string) string

GetTokenRedisKey 获取token缓存Key

func JwtAuth

func JwtAuth() gin.HandlerFunc

JwtAuth JWT鉴权中间件

func OperationRecord

func OperationRecord() gin.HandlerFunc

Types

type CustomClaims

type CustomClaims struct {
	UserInfo           UserInfo // 用户登录信息
	jwt.StandardClaims          // 标准载荷信息
}

CustomClaims

@Description: 自定义Token内容结构

func ParseToken

func ParseToken(tokenStr string) (*CustomClaims, error)

ParseToken token解析方法,返回含有用户信息的数据结构

type OperationRecordData

type OperationRecordData struct {
	Id           int64     `json:"id" form:"id" gorm:"column:id;primary"`
	Ip           string    `json:"ip" form:"ip" gorm:"column:ip;comment:请求ip"`                                   // 请求ip
	CreatedTime  time.Time `json:"createdTime" from:"createdTime" gorm:"column:created_time;comment:创建时间"`       // 记录创建时间
	Method       string    `json:"method" form:"method" gorm:"column:method;comment:请求方法"`                       // 请求方法
	Path         string    `json:"path" form:"path" gorm:"column:path;comment:请求路径"`                             // 请求路径
	Status       int       `json:"status" form:"status" gorm:"column:status;comment:请求状态"`                       // 请求状态
	Latency      int64     `json:"latency" form:"latency" gorm:"column:latency;comment:延迟" swaggertype:"string"` // 延迟
	Agent        string    `json:"agent" form:"agent" gorm:"column:agent;comment:代理"`                            // 代理
	ErrorMessage string    `json:"error_message" form:"error_message" gorm:"column:error_message;comment:错误信息"`  // 错误信息
	Body         string    `json:"body" form:"body" gorm:"type:longtext;column:body;comment:请求Body"`             // 请求Body
	Resp         string    `json:"resp" form:"resp" gorm:"type:longtext;column:resp;comment:响应Body"`             // 响应Body
	UserID       int64     `json:"user_id" form:"user_id" gorm:"column:user_id;comment:用户id"`                    // 用户id
}

OperationRecordData

@Description: 数据记录结构

func (OperationRecordData) TableName

func (OperationRecordData) TableName() string

type UserInfo

type UserInfo struct {
	AccountId  int64  `json:"accountId"`  // 用户ID
	DingtalkId string `json:"dingtalkId"` // 钉钉ID
	UserName   string `json:"userName"`   // 用户名称
	NickName   string `json:"nickName"`   // 用户昵称
	RoleId     string `json:"roleId"`     // 角色ID
}

UserInfo

@Description: 用户登录信息

type UserToRoles

type UserToRoles struct {
	UserId int64  `json:"userId" gorm:"account_myuser_id"`
	RoleId string `json:"roleId" gorm:"authority_role_authority_id"`
}

UserToRoles 临时角色-用户对应表

func (UserToRoles) TableName

func (UserToRoles) TableName() string

Jump to

Keyboard shortcuts

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