Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth struct { Base UserID uuid.UUID `json:"userId" gorm:"column:user_id;not null"` // 用户ID User *User `json:"user" gorm:"foreignkey:UserID"` // 用户 AuthType string `json:"authType" gorm:"column:auth_type;type:VARCHAR(16);not null"` // 鉴权类型 AuthName string `json:"authName" gorm:"column:auth_name;type:VARCHAR(128);not null"` // 鉴权名称 AuthCode *string `json:"authCode" gorm:"column:auth_code" binding:"omitempty"` // 鉴权识别码 VerifyTime *time.Time `json:"verifyTime" gorm:"column:verify_time;type:DATETIME" binding:"omitempty"` // 认证时间 ExpireTime *time.Time `json:"expireTime" gorm:"column:expire_time;type:DATETIME" binding:"omitempty"` // 过期时间 IsEnabled *bool `json:"isEnabled" gorm:"column:is_enabled" binding:"omitempty"` // 是否启用 }
Auth 定义模型 gorm tags参考:https://gorm.io/docs/models.html binding tags参考:https://godoc.org/gopkg.in/go-playground/validator.v8 时间格式比较严格,参考:https://golang.org/pkg/time/#pkg-constants 模型定义中全部使用指针类型,是为了可以插入null值到数据库,但这样会造成一些使用的麻烦 也可以使用"database/sql"或"github.com/guregu/null"包中封装的类型 但是这样会造成binding验证失效,目前没有更好的实现办法,所以暂时全部使用指针类型
type Base ¶
type Base struct { ID uuid.UUID `json:"id" gorm:"column:id;primary_key;not null"` // ID CreatedAt time.Time `json:"createdAt" gorm:"column:created_at;not null"` // 创建时间 UpdatedAt time.Time `json:"updatedAt" gorm:"column:update_at;not null"` // 更新时间 DeletedAt *time.Time `json:"deletedAt" sql:"index" gorm:"column:deleted_at" binding:"omitempty"` // 软删除时间 }
Base 给所有模型共用
type Group ¶
type Group struct { Base Name string `json:"name" gorm:"column:name;type:VARCHAR(32);not null" binding:"min=3,max=20"` // 组名称 LeaderID uuid.UUID `json:"leaderId" gorm:"column:leader_id;not null"` // 队长ID Leader *User `json:"leader" gorm:"foreignkey:LeaderID"` // 队长 Users []*User `json:"users" gorm:"many2many:usergroup;"` // 队员 }
Group 定义模型 gorm tags参考:https://gorm.io/docs/models.html binding tags参考:https://godoc.org/gopkg.in/go-playground/validator.v8 时间格式比较严格,参考:https://golang.org/pkg/time/#pkg-constants 模型定义中全部使用指针类型,是为了可以插入null值到数据库,但这样会造成一些使用的麻烦 也可以使用"database/sql"或"github.com/guregu/null"包中封装的类型 但是这样会造成binding验证失效,目前没有更好的实现办法,所以暂时全部使用指针类型
type Menu ¶
type Menu struct { Base ParentID uuid.UUID `json:"parentId" gorm:"column:parent_id" binding:"omitempty"` // 父ID Parent *Menu `json:"parent" gorm:"foreignkey:ParentID"` // 父菜单 Children []*Menu `json:"children" gorm:"foreignkey:ParentID"` // 子菜单 Name string `json:"name" gorm:"column:name;not null"` // 菜单名称 Path string `json:"path" gorm:"column:path;not null"` // 菜单路径 Icon *string `json:"icon" gorm:"column:icon" binding:"omitempty"` // 菜单图标 Sort *int `json:"sort" gorm:"column:sort" binding:"omitempty"` // 排序 Roles []*Role `json:"roles" gorm:"many2many:rolemenu;"` // 角色 }
Menu 定义模型 gorm tags参考:https://gorm.io/docs/models.html binding tags参考:https://godoc.org/gopkg.in/go-playground/validator.v8 时间格式比较严格,参考:https://golang.org/pkg/time/#pkg-constants 模型定义中全部使用指针类型,是为了可以插入null值到数据库,但这样会造成一些使用的麻烦 也可以使用"database/sql"或"github.com/guregu/null"包中封装的类型 但是这样会造成binding验证失效,目前没有更好的实现办法,所以暂时全部使用指针类型
type Role ¶
type Role struct { Base Name string `json:"name" gorm:"column:name;type:VARCHAR(32);unique;not null" binding:"min=3,max=20"` // 角色名称 Users []*User `json:"users" gorm:"many2many:userrole;"` // 用户 Menus []*Menu `json:"menus" gorm:"many2many:rolemenu;"` // 菜单 }
Role 定义模型 gorm tags参考:https://gorm.io/docs/models.html binding tags参考:https://godoc.org/gopkg.in/go-playground/validator.v8 时间格式比较严格,参考:https://golang.org/pkg/time/#pkg-constants 模型定义中全部使用指针类型,是为了可以插入null值到数据库,但这样会造成一些使用的麻烦 也可以使用"database/sql"或"github.com/guregu/null"包中封装的类型 但是这样会造成binding验证失效,目前没有更好的实现办法,所以暂时全部使用指针类型
type User ¶
type User struct { Base Name string `json:"name" gorm:"column:name;type:VARCHAR(32);not null" binding:"min=3,max=20"` // 姓名 Nickname *string `json:"nickname" gorm:"column:nickname" binding:"omitempty"` // 昵称 Gender *int `json:"gender" gorm:"column:gender;type:TINYINT;default:0" binding:"omitempty,eq=0|eq=1|eq=2"` // 性别 Avatar *string `json:"avatar" gorm:"column:avatar" binding:"omitempty"` // 昵称 Mobile *string `json:"mobile" gorm:"column:mobile;type:VARCHAR(16)" binding:"omitempty"` // 手机 Email *string `json:"email" gorm:"column:email" binding:"omitempty,email"` // 邮箱 Homepage *string `json:"homepage" gorm:"column:homepage" binding:"omitempty,url"` // 个人主页 Birthday *time.Time `json:"birthday" gorm:"column:birthday;type:DATE" binding:"omitempty"` // 生日 Height *float32 `json:"height" gorm:"column:height;type:FLOAT" binding:"omitempty,min=0.01,max=300"` // 身高(cm) BloodType *string `json:"bloodType" gorm:"column:blood_type;type:VARCHAR(8)" binding:"omitempty,eq=A|eq=B|eq=AB|eq=O|eq=NULL"` // 血型(ABO) Notice *string `json:"notice" gorm:"column:notice;type:TEXT" binding:"omitempty"` // 备注 Intro *string `json:"intro" gorm:"column:intro;type:TEXT" binding:"omitempty"` // 简介 Address *string `json:"address" gorm:"column:address;type:JSON" binding:"omitempty"` // 地址 Lives *string `json:"lives" gorm:"column:lives;type:JSON" binding:"omitempty"` // 生活轨迹 Tags *string `json:"tags" gorm:"column:tags;type:JSON" binding:"omitempty"` // 标签 LuckyNumbers *string `json:"luckyNumbers" gorm:"column:lucky_numbers;type:JSON" binding:"omitempty"` // 幸运数字 Score *int `json:"score" gorm:"column:score;default:0" binding:"omitempty"` // 积分 Auths []*Auth `json:"auths" gorm:"foreignkey:UserID"` // 帐号 Roles []*Role `json:"roles" gorm:"many2many:userrole;"` // 角色 Groups []*Group `json:"groups" gorm:"many2many:usergroup;"` // 组 Friends []*User `json:"friends" gorm:"many2many:userfriend;association_jointable_foreignkey:user_id;jointable_foreignkey:friend_id;"` // 友 }
User 用户模型 gorm tags参考:https://gorm.io/docs/models.html binding tags参考:https://godoc.org/gopkg.in/go-playground/validator.v8 时间格式比较严格,参考:https://golang.org/pkg/time/#pkg-constants 模型定义中全部使用指针类型,是为了可以插入null值到数据库,但这样会造成一些使用的麻烦 也可以使用"database/sql"或"github.com/guregu/null"包中封装的类型 但是这样会造成binding验证失效,目前没有更好的实现办法,所以暂时全部使用指针类型
type UserGroup ¶
type UserGroup struct { Base UserID uuid.UUID `json:"userId" gorm:"column:user_id;not null"` // 用户ID User *User `json:"user" gorm:"foreignkey:UserID"` // 用户 GroupID uuid.UUID `json:"groupId" gorm:"column:user_id;not null"` // 组ID Group *Group `json:"group" gorm:"foreignkey:GroupID"` // 组 Level *int `json:"level" gorm:"column:level;type:TINYINT;default:0" binding:"omitempty"` // 级别 JoinTime *time.Time `json:"joinTime" gorm:"column:join_time;type:DATETIME" binding:"omitempty"` // 加入时间 }
UserGroup 定义模型 gorm tags参考:https://gorm.io/docs/models.html binding tags参考:https://godoc.org/gopkg.in/go-playground/validator.v8 时间格式比较严格,参考:https://golang.org/pkg/time/#pkg-constants 模型定义中全部使用指针类型,是为了可以插入null值到数据库,但这样会造成一些使用的麻烦 也可以使用"database/sql"或"github.com/guregu/null"包中封装的类型 但是这样会造成binding验证失效,目前没有更好的实现办法,所以暂时全部使用指针类型