model

package
v0.0.0-...-2f0833a Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Config struct {
	Addr string `default:":8081"`
	DB   struct {
		Type string `required:"true"`
		Host string `required:"true"`
		Port uint64 `yaml:"port,omitempty"`
		User string `required:"true"`
		Pass string `yaml:"pass,omitempty"`
		Name string `yaml:"name,omitempty"`
	}
}

Config 数据库配置项

Functions

func GetAdminNum

func GetAdminNum(filter ...func(*gorm.DB) *gorm.DB) (int64, error)

GetAdminNum 获取用户数量

func GetGroups

func GetGroups() (map[int64]string, error)

GetGroups 获取角色列表

func GetLogNum

func GetLogNum(filter ...func(*gorm.DB) *gorm.DB) (int64, error)

GetLogNum 获取日志数量

func Install

func Install(u *Admin, path string) error

Install 初始化节点

func IsOpen

func IsOpen() bool

IsOpen 数据库是否连接

func Open

func Open(debug bool) (err error)

Open 连接数据库

Types

type Admin

type Admin struct {
	ID        int64  `gorm:"primary_key;auto_increment"`
	Email     string `gorm:"size:255;unique_index;not null"`
	Password  string `gorm:"size:64;not null" json:"-"`
	Salt      string `gorm:"size:10;not null" json:"-"`
	GroupID   int64  `gorm:"not null"`
	Headpic   string `gorm:"size:255"`
	LastIP    string `gorm:"size:16"`
	Status    bool   `gorm:"default:false;not null"`
	LastLogin *time.Time
	CreatedAt *time.Time `gorm:"not null"`
	UpdatedAt *time.Time `json:"-"`
	DeletedAt *time.Time `json:"-"`
	Group     Group      `gorm:"-"`
}

Admin 管理员

func GetAdmins

func GetAdmins(filter ...func(*gorm.DB) *gorm.DB) ([]*Admin, error)

GetAdmins 获取用户列表

func Login

func Login(email, passwd, ip string) (*Admin, error)

Login 用户登录

func (*Admin) Access

func (m *Admin) Access(tpl string) bool

Access 该用户能否访问指定节点

func (*Admin) Create

func (m *Admin) Create() error

Create 注册新用户

func (*Admin) Delete

func (m *Admin) Delete() error

Delete 删除

func (*Admin) GobDecode

func (m *Admin) GobDecode(data []byte) error

GobDecode 反序列化

func (*Admin) GobEncode

func (m *Admin) GobEncode() ([]byte, error)

GobEncode 序列化

func (*Admin) String

func (m *Admin) String() string

func (*Admin) UpdatePasswd

func (m *Admin) UpdatePasswd(v ...interface{}) error

UpdatePasswd 更新密码

type AdminLog

type AdminLog struct {
	ID        int64      `gorm:"primary_key;auto_increment" xlsx:"-"`
	AdminID   int64      `gorm:"not null" xlsx:"-"`
	Admin     *Admin     `xlsx:"用户"`
	Path      string     `gorm:"size:255;not null" xlsx:"路径"`
	UA        string     `gorm:"size:255" xlsx:"-"`
	Commit    string     `gorm:"type:text" xlsx:"注释"`
	IP        string     `gorm:"size:16" xlsx:"IP"`
	CreatedAt *time.Time `gorm:"type(datetime)" xlsx:"时间"`
}

AdminLog 操作日志

func GetLogs

func GetLogs(filter ...func(*gorm.DB) *gorm.DB) ([]*AdminLog, error)

GetLogs 获取日志列表

func (*AdminLog) Create

func (m *AdminLog) Create() error

Create 插入日志

type Group

type Group struct {
	ID    int64   `gorm:"primary_key;auto_increment"`
	Name  string  `gorm:"size:64;unique;not null"`
	Nodes []*Node `gorm:"many2many:node_groups;association_autoupdate:false"`
}

Group 用户组

func (*Group) Create

func (m *Group) Create() error

Create 新建用户组

func (*Group) Select

func (m *Group) Select() error

Select 获取角色

func (*Group) String

func (m *Group) String() string

func (*Group) Update

func (m *Group) Update() error

Update 更新角色

type Menu []*Node

Menu 菜单

func GetNodeAllNodes

func GetNodeAllNodes() (Menu, error)

GetNodeAllNodes 根据用户组获取节点

func GetNodes

func GetNodes() Menu

GetNodes 获取节点树

func (m Menu) Assign(g int64, n *Node) map[string]interface{}

Assign 用于递归生成菜单

type Node

type Node struct {
	ID     int64    `gorm:"primary_key;auto_increment"`
	Name   string   `gorm:"size:64;not null"`
	Parent int64    `gorm:"default:0;not null"`
	Icon   string   `gorm:"size:32;default:null"`
	Remark string   `gorm:"type:text"`
	Path   string   `gorm:"size:255"`
	Type   NodeType `gorm:"default:0;not null"`
	Status bool     `gorm:"default:false;not null"`
	Child  Menu     `gorm:"-"`
	Groups []*Group `gorm:"many2many:node_groups"`
}

Node 节点模型

func GetNodeByPath

func GetNodeByPath(path string) *Node

GetNodeByPath 根据路径查找节点

func (*Node) HasGroup

func (n *Node) HasGroup(id int64) bool

HasGroup 判断指定节点是否能被某角色访问

func (*Node) HasParent

func (n *Node) HasParent(id int64) bool

HasParent 判断父节点是否存在

func (*Node) Parents

func (n *Node) Parents() []*Node

Parents 获取指定节点的所有父节点

func (*Node) String

func (n *Node) String() string

type NodeType

type NodeType int8

NodeType 节点类型

const (
	// NodeTypeNormal 普通节点
	NodeTypeNormal NodeType = iota
	// NodeTypeEssensial 必要节点
	NodeTypeEssensial
	// NodeTypeFix 不可修改节点
	NodeTypeFix
)

Jump to

Keyboard shortcuts

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