gtoken

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheModeCache = 1
	CacheModeRedis = 2

	MiddlewareTypeGroup  = 1
	MiddlewareTypeBind   = 2
	MiddlewareTypeGlobal = 3
)
View Source
const (
	SUCCESS      = 0
	FAIL         = -1
	ERROR        = -99
	UNAUTHORIZED = -401
	//配置
	TypeConfig = 1
	//  字典
	TypeDict = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GfToken

type GfToken struct {
	// GoFrame server name
	ServerName string
	// 缓存模式 1 gcache 2 gredis 默认1
	CacheMode int8
	// 缓存key
	CacheKey string
	// 超时时间 默认10天(毫秒)
	Timeout int
	// 缓存刷新时间 默认为超时时间的一半(毫秒)
	MaxRefresh int
	// Token分隔符
	TokenDelimiter string
	// Token加密key
	EncryptKey []byte
	// 认证失败中文提示
	AuthFailMsg string
	// 是否支持多端登录,默认false
	MultiLogin bool
	// 是否是全局认证,兼容历史版本,已废弃
	GlobalMiddleware bool
	// 中间件类型 1 GroupMiddleware 2 BindMiddleware  3 GlobalMiddleware
	MiddlewareType uint

	// 登录路径
	LoginPath string
	// 登录验证方法 return userKey 用户标识 如果userKey为空,结束执行
	LoginBeforeFunc func(r *ghttp.Request) (string, interface{})
	// 登录返回方法
	LoginAfterFunc func(r *ghttp.Request, respData Resp)
	// 登出地址
	LogoutPath string
	// 登出验证方法 return true 继续执行,否则结束执行
	LogoutBeforeFunc func(r *ghttp.Request) bool
	// 登出返回方法
	LogoutAfterFunc func(r *ghttp.Request, respData Resp)

	// 拦截地址
	AuthPaths g.SliceStr
	// 拦截排除地址
	AuthExcludePaths g.SliceStr
	// 认证验证方法 return true 继续执行,否则结束执行
	AuthBeforeFunc func(r *ghttp.Request) bool
	// 认证返回方法
	AuthAfterFunc func(r *ghttp.Request, respData Resp)
}

GfToken gtoken结构体

func (*GfToken) AuthPath

func (m *GfToken) AuthPath(urlPath string) bool

判断路径是否需要进行认证拦截 return true 需要认证

func (*GfToken) DecryptToken

func (m *GfToken) DecryptToken(token string) Resp

DecryptToken token解密方法

func (*GfToken) EncryptToken

func (m *GfToken) EncryptToken(userKey string, uuid string) Resp

EncryptToken token加密方法

func (*GfToken) GetTokenData

func (m *GfToken) GetTokenData(r *ghttp.Request) Resp

GetTokenData 通过token获取对象

func (*GfToken) InitConfig

func (m *GfToken) InitConfig() bool

InitConfig 初始化配置信息

func (*GfToken) Login

func (m *GfToken) Login(r *ghttp.Request)

Login 登录

func (*GfToken) Logout

func (m *GfToken) Logout(r *ghttp.Request)

Logout 登出

func (*GfToken) Middleware

func (m *GfToken) Middleware(group *ghttp.RouterGroup) bool

绑定group

func (*GfToken) MiddlewareEx added in v1.4.7

func (m *GfToken) MiddlewareEx(group *ghttp.RouterGroup) bool

MiddlewareEx 绑定group,不增加route

func (*GfToken) RemoveToken

func (m *GfToken) RemoveToken(token string) Resp

removeToken 删除Token

func (*GfToken) Start

func (m *GfToken) Start() bool

Start 启动

func (*GfToken) Stop

func (m *GfToken) Stop() bool

Start 结束

func (*GfToken) String

func (m *GfToken) String() string

String token解密方法

type Resp

type Resp struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func Error

func Error(msg string) Resp

错误

func ErrorData

func ErrorData(msg string, data interface{}) Resp

错误设置Data

func Fail

func Fail(msg string) Resp

失败

func FailData

func FailData(msg string, data interface{}) Resp

失败设置Data

func Succ

func Succ(data interface{}) Resp

成功

func Unauthorized

func Unauthorized(msg string, data interface{}) Resp

认证失败

func (Resp) DataInt

func (resp Resp) DataInt() int

获取Data转Int

func (Resp) DataString

func (resp Resp) DataString() string

获取Data转字符串

func (Resp) Get

func (resp Resp) Get(key string) interface{}

获取Data值

func (Resp) GetInt

func (resp Resp) GetInt(key string) int

获取Data值转Int

func (Resp) GetString

func (resp Resp) GetString(key string) string

获取Data值转字符串

func (Resp) Json

func (resp Resp) Json() string

func (Resp) Success

func (resp Resp) Success() bool

获取Data值转字符串

Jump to

Keyboard shortcuts

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