util

package
v0.0.0-...-a9e7740 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2020 License: Artistic-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KEY                    string = "JWT_ARY-START"
	DEFAULT_EXPIRE_SECONDS int    = 7200 //默认过期时间
)
View Source
const (
	CmsRoleKey      = iota //0 后台角色 key
	CmsRouteKey            // 1 后台路由 key
	CmsUserLoginKey        // 2 后台用户登录 key
	JobTaskRunLog          // 4 定时任务执行日志
	MessageQueue           // 4 消息通知和队列
)

Variables

View Source
var (
	MgoClient = &MongoObj{}
)
View Source
var RedisKeyList = map[int]string{

	CmsRoleKey:      "CmsRoleInfo",
	CmsRouteKey:     "CmsRouteInfo",
	CmsUserLoginKey: "CmsUserLoginInfo_",
	JobTaskRunLog:   "JobTaskRunLog",
	MessageQueue:    "MessageQueue",
}

redis key管理集合

View Source
var (
	RedisObj = &RedisOp{}
)

Functions

func GenerateToken

func GenerateToken(info *AdminJwtData, expiredSeconds int) (tokenString string, err error)

获取jwt token

func MongoInit

func MongoInit()

func RedisInit

func RedisInit()

初始化连接redis

func RefreshToken

func RefreshToken(tokenString string, expiredSeconds int) (string, error)

刷新jwt token

Types

type AdminJwtData

type AdminJwtData struct {
	Id       int
	RealName string
	Sex      int8
}

管理员 token数据

func ValidateToken

func ValidateToken(tokenString string) (info *AdminJwtData, err error)

验证jwt token

type Claims

type Claims struct {
	Admin *AdminJwtData
	jwt.StandardClaims
}

JWT -- json web token HEADER PAYLOAD SIGNATURE This struct is the PAYLOAD

type MongoObj

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

func (*MongoObj) Aggregate

func (m *MongoObj) Aggregate(db, tableName string, pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error)

聚合查询

func (*MongoObj) CountDocuments

func (m *MongoObj) CountDocuments(db, tableName string, filter interface{}) (int64, error)

func (*MongoObj) Find

func (m *MongoObj) Find(db, tableName string, document, filter interface{}, opts ...*options.FindOptions) (int64, error)

func (*MongoObj) FindOne

func (m *MongoObj) FindOne(db, tableName string, filter, document interface{}, opts ...*options.FindOneOptions) error

func (*MongoObj) InsertOne

func (m *MongoObj) InsertOne(db, tableName string, document interface{}) (*mongo.InsertOneResult, error)

func (*MongoObj) UpdateOne

func (m *MongoObj) UpdateOne(db, tableName string, filter, document interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

type RedisOp

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

func (*RedisOp) Del

func (c *RedisOp) Del(key string) error

func (*RedisOp) Exists

func (c *RedisOp) Exists(key string) bool

返回key是否存在

func (*RedisOp) Expire

func (c *RedisOp) Expire(key string, expired int) bool

设置过期时间 单位秒

func (*RedisOp) Get

func (c *RedisOp) Get(key string) (result interface{}, err error)

func (*RedisOp) LPush

func (c *RedisOp) LPush(key string, value interface{}) error

func (*RedisOp) RPop

func (c *RedisOp) RPop(key string) (result interface{}, err error)

func (*RedisOp) Set

func (c *RedisOp) Set(key string, value interface{}) error

func (*RedisOp) SetEx

func (c *RedisOp) SetEx(key string, timeout time.Duration, value interface{}) error

func (*RedisOp) Ttl

func (c *RedisOp) Ttl(key string) int64

返回过期时间 单位:秒 -2不存在或已过期 -1永不过期

Jump to

Keyboard shortcuts

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