Documentation ¶
Index ¶
- Constants
- Variables
- func ComparePassword(hashPassword, password string) error
- func Fail(statusCode int, message string, c *gin.Context)
- func FailAuthorization(message string, c *gin.Context)
- func FailDefault(c *gin.Context)
- func FailWithMessage(message string, c *gin.Context)
- func FormatJwtExpiresTime(dur int) *jwt.NumericDate
- func HashPassword(password string) (string, error)
- func Ok(data any, c *gin.Context)
- func OkDefault(c *gin.Context)
- func Resp(statusCode int, data any, message string, c *gin.Context)
- type JwtCustomClaims
- type JwtSign
- func (*JwtSign) CreateClaims(userId string, username string) *JwtCustomClaims
- func (j *JwtSign) CreateToken(userId string, username string) (string, error)
- func (j *JwtSign) ParseToken(token string) (*JwtCustomClaims, error)
- func (j *JwtSign) RefreshToken(token string) (userId string, nToken string, err error)
- type Response
Constants ¶
View Source
const ( SuccessCode = 200 SuccessMessage = "success" ErrorCode = 0 ErrorAuthorizationCode = 401 ErrorMessage = "fail" )
Variables ¶
View Source
var TokenExpired = errors.New("token is expired")
Functions ¶
func ComparePassword ¶
ComparePassword 密码校验
func FailAuthorization ¶
func FailWithMessage ¶
FailWithMessage 失败, 返回失败信息
func FormatJwtExpiresTime ¶
func FormatJwtExpiresTime(dur int) *jwt.NumericDate
Types ¶
type JwtCustomClaims ¶
type JwtSign ¶
type JwtSign struct {
SingingKey []byte
}
func (*JwtSign) CreateClaims ¶
func (*JwtSign) CreateClaims(userId string, username string) *JwtCustomClaims
CreateClaims 创建claims
func (*JwtSign) CreateToken ¶
CreateToken 创建Token
func (*JwtSign) ParseToken ¶
func (j *JwtSign) ParseToken(token string) (*JwtCustomClaims, error)
ParseToken 解析(验证)Token
Click to show internal directories.
Click to hide internal directories.