model

package
v0.0.0-...-c676f21 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	UserId uint64
	jwt.StandardClaims
}

type CreateDelete

type CreateDelete struct {
	Id     uint64   `json:"id"`     // 需更新记录的id
	Create []uint64 `json:"create"` // 需删除的关联id (角色id 或 菜单id 或 接口id)
	Delete []uint64 `json:"delete"` // 需增加的关联id (角色id 或 菜单id 或 接口id)
}

type DeletedAt

type DeletedAt struct {
	time.Time
}

由于gorm提供的DeletedAt没有json tag, 因此自定义为yyyy-MM-dd hh:mm:ss格式

func (DeletedAt) DeleteClauses

func (DeletedAt) DeleteClauses(f *schema.Field) []clause.Interface

func (*DeletedAt) MarshalJSON

func (t *DeletedAt) MarshalJSON() ([]byte, error)

重写time.Time的MarshalJSON方法

func (DeletedAt) QueryClauses

func (DeletedAt) QueryClauses(f *schema.Field) []clause.Interface

func (*DeletedAt) Scan

func (t *DeletedAt) Scan(v interface{}) error

实现sql包中的Scanner接口,被Rows和Row的Scan方法使用

func (*DeletedAt) SetString

func (t *DeletedAt) SetString(str string) *DeletedAt

设置字符串

func (*DeletedAt) UnmarshalJSON

func (t *DeletedAt) UnmarshalJSON(data []byte) error

重写time.Time的UnmarshalJSON方法

func (DeletedAt) UpdateClauses

func (DeletedAt) UpdateClauses(f *schema.Field) []clause.Interface

func (DeletedAt) Value

func (t DeletedAt) Value() (driver.Value, error)

实现driver包中的Valuer接口,将自定义的类型值转换为驱动支持的Value类型值,ps: 接收器不能是指针类型,否则会报invalid memory address or nil pointer dereference

type IdParam

type IdParam struct {
	Ids string `json:"ids" form:"ids"`
}

type LocalTime

type LocalTime struct {
	time.Time
}

定义为常用的yyyy-MM-dd hh:mm:ss

func (LocalTime) MarshalJSON

func (t LocalTime) MarshalJSON() ([]byte, error)

重写time.Time的MarshalJSON方法

func (*LocalTime) Scan

func (t *LocalTime) Scan(v interface{}) error

实现sql包中的Scanner接口,会被Rows或Row的Scan方法调用

func (*LocalTime) UnmarshalJSON

func (t *LocalTime) UnmarshalJSON(data []byte) error

重写time.Time的UnmarshalJSON方法

func (LocalTime) Value

func (t LocalTime) Value() (driver.Value, error)

实现driver中的Valuer接口,将自定义类型值转换为驱动支持的Value类型值,ps: 接收器不能是指针类型,否则会报invalid memory address or nil pointer dereference

type Login

type Login struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type Model

type Model struct {
	Id        uint64     `gorm:"primaryKey;comment:'自增编号'" json:"id"`
	CreatedAt LocalTime  `gorm:"comment:'创建时间'" json:"createdAt"`
	UpdatedAt LocalTime  `gorm:"comment:'更新时间'" json:"updatedAt"`
	DeletedAt *DeletedAt `gorm:"index:idx_deleted_at;comment:'删除时间(软删除)'" json:"deletedAt"`
}

gorm提供的Model没有json tag,因此进行自定义

type Page

type Page struct {
	Records interface{} `json:"records"`
	Total   int64       `json:"total"`
	PageNum int         `json:"pageNum"`
	PageInfo
}

分页

func (*Page) SetPageNum

func (p *Page) SetPageNum(count int64)

type PageInfo

type PageInfo struct {
	PageIndex int `json:"pageIndex"`
	PageSize  int `json:"pageSize"`
}

分页参数

type SoftDeleteDeleteClause

type SoftDeleteDeleteClause struct {
	Field *schema.Field
}

func (SoftDeleteDeleteClause) Build

func (SoftDeleteDeleteClause) MergeClause

func (sd SoftDeleteDeleteClause) MergeClause(*clause.Clause)

func (SoftDeleteDeleteClause) ModifyStatement

func (sd SoftDeleteDeleteClause) ModifyStatement(stmt *gorm.Statement)

func (SoftDeleteDeleteClause) Name

func (sd SoftDeleteDeleteClause) Name() string

type SoftDeleteQueryClause

type SoftDeleteQueryClause struct {
	Field *schema.Field
}

func (SoftDeleteQueryClause) Build

func (SoftDeleteQueryClause) MergeClause

func (sd SoftDeleteQueryClause) MergeClause(*clause.Clause)

func (SoftDeleteQueryClause) ModifyStatement

func (sd SoftDeleteQueryClause) ModifyStatement(stmt *gorm.Statement)

func (SoftDeleteQueryClause) Name

func (sd SoftDeleteQueryClause) Name() string

type SoftDeleteUpdateClause

type SoftDeleteUpdateClause struct {
	Field *schema.Field
}

func (SoftDeleteUpdateClause) Build

func (SoftDeleteUpdateClause) MergeClause

func (sd SoftDeleteUpdateClause) MergeClause(*clause.Clause)

func (SoftDeleteUpdateClause) ModifyStatement

func (sd SoftDeleteUpdateClause) ModifyStatement(stmt *gorm.Statement)

func (SoftDeleteUpdateClause) Name

func (sd SoftDeleteUpdateClause) Name() string

type SysApi

type SysApi struct {
	Model
	Method   string   `gorm:"not null;comment:'请求方式'" json:"method"`
	Path     string   `gorm:"not null;comment:'访问路径'" json:"path"`
	Category string   `gorm:"comment:'所属类别'" json:"category"`
	Desc     string   `gorm:"comment:'说明'" json:"desc"`
	Creator  string   `gorm:"comment:'创建人'" json:"creator"`
	Roles    []uint64 `gorm:"-" json:"roles"`
}

func (*SysApi) TableName

func (a *SysApi) TableName() string

type SysApiPage

type SysApiPage struct {
	SysApi
	PageInfo
}

type SysCasbin

type SysCasbin struct {
	Id    uint64 `gorm:"primaryKey;autoIncrement"`
	Ptype string `gorm:"colument:ptype;size:100;index:idx_casbin_unique;comment:'策略类型'" json:"type"`
	V0    string `gorm:"size:100;index:idx_casbin_unique;comment:'角色关键字'" json:"roleKey"`
	V1    string `gorm:"size:100;index:idx_casbin_unique;comment:'资源名称'" json:"uri"`
	V2    string `gorm:"size:100;index:idx_casbin_unique;comment:'请求类型'" json:"method"`
	V3    string `gorm:"size:100;index:idx_casbin_unique;"`
	V4    string `gorm:"size:100;index:idx_casbin_unique;"`
	V5    string `gorm:"size:100;index:idx_casbin_unique;"`
}

func (*SysCasbin) TableName

func (c *SysCasbin) TableName() string

type SysCasbinPage

type SysCasbinPage struct {
	SysCasbin
	PageInfo
}

type SysMenu

type SysMenu struct {
	Model
	Name      string    `gorm:"comment:'菜单英文名称'" json:"name"`
	Title     string    `gorm:"comment:'菜单标题(中文名称)'" json:"title"`
	Icon      string    `gorm:"comment:'菜单图标'" json:"icon"`
	Path      string    `gorm:"comment:'菜单前端访问路径'" json:"path"`
	Redirect  string    `gorm:"comment:'重定向路径'" json:"redirect"`
	Component string    `gorm:"comment:'前端组件路径'" json:"component"`
	Sort      *uint     `gomr:"type:int unsigned;comment:'菜单顺序(同级比较越小越前)'" json:"sort"`            // 定义为指针类型可以避免默认值为0的情况
	Status    *bool     `gorm:"type:tinyint(1);default:1;comment:'菜单状态(0:禁用,1:启动)'" json:"status"` // 定义为指针类型可以避免默认值为false的情况
	ParentId  uint64    `gorm:"column:parent_id;not null;" json:"parent_id" form:"parentId"`
	Children  []SysMenu `gorm:"-" json:"children"`
	Roles     []SysRole `gorm:"many2many:sys_role_menu_relation;" json:"roles"` // 角色菜单多对多关系表
}

func (*SysMenu) TableName

func (m *SysMenu) TableName() string

type SysMenuPage

type SysMenuPage struct {
	SysMenu
	PageInfo
}

type SysRole

type SysRole struct {
	Model
	Name   string    `gorm:"column:name;size:32;not null;comment:'角色名称'" json:"name" `
	NameZh string    `gorm:"column:name_zh;size:32;comment:'角色中文名称'"  json:"nameZh" `
	Sort   *uint     `gorm:"column:sort;default:1;comment:'角色权限顺序:(顺序越小权限越大)'" json:"sort" `
	Status *bool     `gorm:"column:status;type:tinyint(1);default:1;comment:'角色状态:(0:禁用,1:启用)'" json:"status" `
	Menus  []SysMenu `gorm:"many2many:sys_role_menu_relation;" json:"menus"` // 角色菜单多对多关系表
	Users  []SysUser `gorm:"many2many:sys_user_role_relation;" json:"users"` // 用户角色多对多关系表
}

func (*SysRole) TableName

func (r *SysRole) TableName() string

重命名表名

type SysRoleCasbin

type SysRoleCasbin struct {
	Kyeword string `json:"keyword"` // 按角色,对应casbin的v0
	Path    string `json:"path"`    // 对应casbin的v1
	Method  string `josn:"method"`  // 对应casbin的v2
}

type SysRolePage

type SysRolePage struct {
	SysRole
	PageInfo
}

分页查询参数接收体

type SysUser

type SysUser struct {
	Model
	Username string    ` gorm:"column:username;size:32;not null;comment:'用户名'" json:"username" form:"username" `
	Password string    ` gorm:"column:password;size:64;not null;comment:'密码'" json:"password" form:"password" `
	Status   *bool     `` /* 133-byte string literal not displayed */
	Roles    []SysRole `gorm:"many2many:sys_user_role_relation;" json:"roles"`
}

func (*SysUser) TableName

func (u *SysUser) TableName() string

重命名表名

type SysUserPage

type SysUserPage struct {
	SysUser
	PageInfo
}

分页查询参数接收体

type SysUserResponse

type SysUserResponse struct {
	Model
	Username string    `json:"username"`
	Status   *bool     `json:"status"`
	Roles    []SysRole `json:"roles"`
}

用户信息响应结构体,数据脱敏

type WhereOrder

type WhereOrder struct {
	Order string
	Where string
	Value []interface{}
}

sql的条件,可以自由再添加or,limit,offset

Jump to

Keyboard shortcuts

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