system

package
v0.0.0-...-da6f084 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenExpired     error  = errors.New("Token 已经过期")
	TokenNotValidYet error  = errors.New("Token 尚未激活")
	TokenMalformed   error  = errors.New("Token 格式错误")
	TokenInvalid     error  = errors.New("Token 无法解析")
	SignKey          string = "82040620FEFAC4511FC65000ADAB0F77"
)

定义一些常量

Functions

func GetConfig

func GetConfig() *config

获取配置文件

func GetDatasource

func GetDatasource() (datasource *datasource)

获取数据库连接配置

func GetGinConfig

func GetGinConfig() (ginconfig *ginConfig)

获取 gin 配置

func GetServerConfig

func GetServerConfig() (serverconfig *serverConfig)

获取项目启动配置

func GetSignKey

func GetSignKey() string

获取 signKey

func GetTokenConfig

func GetTokenConfig() (tokenconfig *tokenConfig)

获取Token配置

func JWTAuth

func JWTAuth() gin.HandlerFunc

func LoadConfig

func LoadConfig(path string) error

如果配置文件写成一个文件,调下面的方法

func LoadDatasourceConfig

func LoadDatasourceConfig(path string) error

func LoadServerConfig

func LoadServerConfig(path string) error

func LoadTokenConfig

func LoadTokenConfig(path string) error

func Logger

func Logger(log *logrus.Logger) gin.HandlerFunc

定义 基于logrus 的log中间件

func SetSignKey

func SetSignKey(key string) string

Types

type CustomClaims

type CustomClaims struct {
	ID    string `json:"userId"`
	Name  string `json:"name"`
	Phone string `json:"phone"`
	jwt.StandardClaims
}

载荷,加一些系统需要的信息

type JWT

type JWT struct {
	SigningKey []byte
}

jwt签名结构

func NewJWT

func NewJWT() *JWT

新建一个 jwt 实例

func (*JWT) CreateToken

func (j *JWT) CreateToken(claims CustomClaims) (string, error)

生成 tokenConfig

func (*JWT) RefreshToken

func (j *JWT) RefreshToken(tokenString string) (string, error)

更新token

func (*JWT) ResolveToken

func (j *JWT) ResolveToken(tokenString string) (*CustomClaims, error)

解析 tokenConfig

Jump to

Keyboard shortcuts

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