Documentation ¶
Index ¶
- Constants
- Variables
- func CheckTokenVerify(conf ...HandlerConfig) gin.HandlerFunc
- func ErrorTokenAuthFail(c *gin.Context)
- func ErrorTokenBaseInfo(c *gin.Context)
- func ErrorTokenRefreshFail(c *gin.Context)
- func HandleTokenVerify(conf ...HandlerConfig) gin.HandlerFunc
- func Init()
- func RefreshTokenConditionCheck() gin.HandlerFunc
- func TokenErrorParam(c *gin.Context)
- type ErrorHandleFunc
- type HandlerConfig
Constants ¶
View Source
const ( ErrorsParseTokenFail string = "解析token失败" ErrorsTokenBaseInfo string = "token最基本的格式错误,请提供一个有效的token!" ErrorsNoAuthorization string = "token鉴权未通过,请通过token授权接口重新获取token," ErrorsRefreshTokenFail string = "token不符合刷新条件,请通过登陆接口重新获取token!" ValidatorParamsCheckFailCode int = -400300 ValidatorParamsCheckFailMsg string = "参数校验失败" )
Variables ¶
View Source
var ( // DefaultConfig is the default middleware config. DefaultConfig = HandlerConfig{ ErrorHandleFunc: func(ctx *gin.Context, err error) { if err != nil { logger.Error("Internal Server Error: ", err.Error()) } else { logger.Error("Internal Server Error: ", "unknown") } }, TokenKey: "token", Skipper: func(_ *gin.Context) bool { return false }, } )
Functions ¶
func CheckTokenVerify ¶
func CheckTokenVerify(conf ...HandlerConfig) gin.HandlerFunc
CheckTokenVerify Verify the access token of the middleware 如果有用户信息,则设置用户信息,没有则设置为空,允许公开访问
func HandleTokenVerify ¶
func HandleTokenVerify(conf ...HandlerConfig) gin.HandlerFunc
HandleTokenVerify Verify the access token of the middleware 只有登录获取授权后才可以访问
func RefreshTokenConditionCheck ¶
func RefreshTokenConditionCheck() gin.HandlerFunc
RefreshTokenConditionCheck 刷新token条件检查中间件,针对已经过期的token,要求是token格式以及携带的信息满足配置参数即可
Types ¶
type ErrorHandleFunc ¶
ErrorHandleFunc error handling function
type HandlerConfig ¶
type HandlerConfig struct { // error handling when starting the session ErrorHandleFunc ErrorHandleFunc // keys stored in the context TokenKey string // defines a function to skip middleware.Returning true skips processing // the middleware. Skipper func(*gin.Context) bool }
Config defines the config for Session middleware
Click to show internal directories.
Click to hide internal directories.