common

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2020 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_TIMEOUT     = 86400 * 30 // 接近无限时间
	SESS_ONLINE_KEY = "onlines"  // 在线用户
	SESS_TOKEN_KEY  = "_token_"
	SESS_PREFIX     = "sess" // 会话缓存前缀
	SESS_TIMEOUT    = 7200   // 会话缓存时间
	SESS_LIST_SEP   = ";"    // 角色名之间的分隔符
)

Variables

This section is empty.

Functions

func GetColumns added in v0.9.1

func GetColumns(m ITableName) []string

获取Model的字段列表

func GetPrimarykey added in v0.9.1

func GetPrimarykey(engine *xorm.Engine, m interface{}) *schemas.Column

获取Model的字段列表

func JoinQuery added in v0.9.1

func JoinQuery(engine *xorm.Engine, native, foreign ITableName, fkey, pkey, joinOp string) *xorm.Session

联表查询

func LeftJoinQuery added in v0.9.1

func LeftJoinQuery(engine *xorm.Engine, native, foreign ITableName, fkey string) *xorm.Session

Left Join 联表查询

func MoveEdge

func MoveEdge(query *xorm.Session, base uint, offset string) error

左右边界整体移动

func NegativeOffset added in v0.3.1

func NegativeOffset(offset, pagesize, total int) int

调整从后往前翻页

func Paginate

func Paginate(query *xorm.Session, pageno, pagesize int) *xorm.Session

计算翻页

func Qprintf added in v0.9.1

func Qprintf(engine *xorm.Engine, format string, args ...interface{}) string

对参数先进行转义Quote

func SessListJoin

func SessListJoin(data []string) string

func SessListSplit

func SessListSplit(data string) []string

Types

type FilterFunc

type FilterFunc = func(query *xorm.Session) *xorm.Session

过滤查询

type ITableComment

type ITableComment interface {
	TableComment() string
}

*

  • 数据表注释

type ITableName

type ITableName interface {
	TableName() string
}

*

  • 数据表名

type ModifyFunc added in v0.3.3

type ModifyFunc = func(tx *xorm.Session) (int64, error)

修改操作,用于事务

type NestedMixin added in v0.3.3

type NestedMixin struct {
	Lft   int `json:"lft" xorm:"notnull default 0 comment('左边界') INT(10)"`           // 左边界
	Rgt   int `json:"rgt" xorm:"notnull default 0 comment('右边界') index INT(10)"`     // 右边界
	Depth int `json:"depth" xorm:"notnull default 1 comment('高度') index TINYINT(3)"` // 高度
}

嵌套集合树

func (*NestedMixin) AddToParent added in v0.3.3

func (n *NestedMixin) AddToParent(parent *NestedMixin, tbQuery *xorm.Session) error

添加到父节点最末,tbQuery一定要使用db.Table(...)

func (NestedMixin) AncestorsFilter added in v0.3.3

func (n NestedMixin) AncestorsFilter(backward bool) FilterFunc

找出所有直系祖先节点

func (NestedMixin) ChildrenFilter added in v0.3.3

func (n NestedMixin) ChildrenFilter(rank uint8) FilterFunc

找出所有子孙节点

func (NestedMixin) CountChildren added in v0.3.3

func (n NestedMixin) CountChildren() int

有多少个子孙节点

func (NestedMixin) IsLeaf added in v0.3.3

func (n NestedMixin) IsLeaf() bool

是否叶子节点

type Session

type Session struct {
	*redisw.RedisHash
	// contains filtered or unexported fields
}

func NewSession

func NewSession(reg *SessionRegistry, key string) *Session

func (*Session) AddFlash

func (sess *Session) AddFlash(messages ...string) (int, error)

func (*Session) BindRoles

func (sess *Session) BindRoles(uid string, roles []string, kick bool) (string, error)

绑定用户角色,返回旧的sid

func (*Session) GetFlashes

func (sess *Session) GetFlashes(n int) ([]string, error)

数量n为最大取出多少条消息,-1表示所有消息

func (*Session) GetKey

func (sess *Session) GetKey() string

type SessionRegistry

type SessionRegistry struct {
	Onlines *redisw.RedisHash
	*redisw.RedisWrapper
	// contains filtered or unexported fields
}

func InitCache

func InitCache(c config.ConnConfig, verbose bool) (*SessionRegistry, error)

func NewRegistry

func NewRegistry(w *redisw.RedisWrapper) *SessionRegistry

func (*SessionRegistry) DelSession

func (sr *SessionRegistry) DelSession(token string) bool

func (SessionRegistry) GetKey

func (sr SessionRegistry) GetKey(token string) string

func (*SessionRegistry) GetSession

func (sr *SessionRegistry) GetSession(token string) *Session

type TimeMixin added in v0.3.3

type TimeMixin struct {
	CreatedAt time.Time `json:"created_at" xorm:"created comment('创建时间') TIMESTAMP"`       // 创建时间
	UpdatedAt time.Time `json:"updated_at" xorm:"updated comment('更新时间') TIMESTAMP"`       // 更新时间
	DeletedAt time.Time `json:"deleted_at" xorm:"deleted comment('删除时间') index TIMESTAMP"` // 删除时间
}

*

  • 时间相关的三个典型字段

Jump to

Keyboard shortcuts

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