lib

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

LibSet 服务providers

Functions

This section is empty.

Types

type AppClaims

type AppClaims struct {
	IsAdmin bool `json:"isadmin"`
	jwt.RegisteredClaims
}

AppClaims 自定义claims

type JwtService

type JwtService struct {
	Conf *conf.Jwt
	// contains filtered or unexported fields
}

JwtAuth 提供jwt相关服务

func NewJwtService

func NewJwtService(cfg *conf.Config, redis *redis.Client) *JwtService

func (*JwtService) GenToken

func (s *JwtService) GenToken(iss string, isAdmin bool, user JwtUser) (*TokenOutput, error)

GenToken 创建token

func (*JwtService) IsInBlackList

func (s *JwtService) IsInBlackList(tokenStr string) bool

IsInBlackList 查询token是否在黑名单中

func (*JwtService) JoinBlackList

func (s *JwtService) JoinBlackList(tokenStr string) error

JoinBlackList 将token加入黑名单

func (*JwtService) RequestAuth

func (s *JwtService) RequestAuth(iss string, authStr string) (*AppClaims, *jwt.Token, error)

RequestAuth 请求头jwt认证

type JwtUser

type JwtUser interface {
	GetUid() string // 获取用户id
	GetPwd() string // 获取用户秘密
}

JwtUser 签名实例需要实现的接口

type Login

type Login struct {
	Phone    string `form:"phone" json:"phone" binding:"required,len=11,number"`
	Password string `form:"password" json:"password" binding:"required,gte=6"`
	IsAdmin  bool   `form:"category" json:"category" default:"false"`
}

Login 登录信息

func (Login) GetMessages

func (login Login) GetMessages() request.ValidatorMessages

GetMessages 实现request.Validator接口

type Register

type Register struct {
	Name     string `form:"name" json:"name" binding:"required"`                 // user name
	Phone    string `form:"phone" json:"phone" binding:"required,len=11,number"` // phone
	Password string `form:"password" json:"password" binding:"required,gte=6"`   // password
	IsAdmin  bool   `form:"category" json:"category" default:"false"`
}

Register 注册信息

func (Register) GetMessages

func (register Register) GetMessages() request.ValidatorMessages

GetMessages 实现request.Validator接口

type TokenOutput

type TokenOutput struct {
	Token   string `json:"token"`
	Expires int    `json:"expires"`
	Type    string `json:"type"`
}

TokenOutput token输出格式

type UserService

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

UserService 提供user相关服务

func NewUserService

func NewUserService(db *gorm.DB) *UserService

NewUserService 创建user服务

func (*UserService) GetUserInfo

func (s *UserService) GetUserInfo(id string, isAdmin bool) (JwtUser, error)

GetUserInfo 获取单个用户信息

func (*UserService) SignIn

func (s *UserService) SignIn(params Login) (JwtUser, error)

SignIn 用户登录

func (*UserService) SignUp

func (s *UserService) SignUp(params Register) (JwtUser, error)

SignUp 用户注册

Jump to

Keyboard shortcuts

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