🎨 add gorm cache & update model structure
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
NotDeleted int64 = iota
|
||||
Deleted int64 = 1
|
||||
)
|
@@ -1,6 +1,7 @@
|
||||
Name: main
|
||||
Host: 0.0.0.0
|
||||
Port: 80
|
||||
MaxConns: 100
|
||||
Web:
|
||||
URL: http://localhost:5173
|
||||
Middlewares:
|
||||
|
@@ -59,13 +59,9 @@ func (l *SubmitCommentLogic) SubmitComment(r *http.Request, req *types.CommentRe
|
||||
browser, _ := ua.Browser()
|
||||
operatingSystem := ua.OS()
|
||||
var isAuthor int64 = 0
|
||||
session, err := l.svcCtx.Session.Get(r, constant.SESSION_KEY)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uid, ok := session.Values["uid"].(string)
|
||||
uid, ok := l.ctx.Value("user_id").(string)
|
||||
if !ok {
|
||||
return nil, errors.New("uid not found in session")
|
||||
return nil, errors.New("user_id not found in context")
|
||||
}
|
||||
if uid == req.Author {
|
||||
isAuthor = 1
|
||||
|
@@ -57,14 +57,9 @@ func (l *SubmitReplyCommentLogic) SubmitReplyComment(r *http.Request, req *types
|
||||
|
||||
browser, _ := ua.Browser()
|
||||
operatingSystem := ua.OS()
|
||||
session, err := l.svcCtx.Session.Get(r, constant.SESSION_KEY)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uid, ok := session.Values["uid"].(string)
|
||||
uid, ok := l.ctx.Value("user_id").(string)
|
||||
if !ok {
|
||||
return nil, errors.New("uid not found in session")
|
||||
return nil, errors.New("user_id not found in context")
|
||||
}
|
||||
var isAuthor int64 = 0
|
||||
if uid == req.Author {
|
||||
|
@@ -64,14 +64,9 @@ func (l *SubmitReplyReplyLogic) SubmitReplyReply(r *http.Request, req *types.Rep
|
||||
browser, _ := ua.Browser()
|
||||
operatingSystem := ua.OS()
|
||||
|
||||
// 获取用户会话信息
|
||||
session, err := l.svcCtx.Session.Get(r, constant.SESSION_KEY)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uid, ok := session.Values["uid"].(string)
|
||||
uid, ok := l.ctx.Value("user_id").(string)
|
||||
if !ok {
|
||||
return nil, errors.New("uid not found in session")
|
||||
return nil, errors.New("user_id not found in context")
|
||||
}
|
||||
|
||||
// 判断作者身份
|
||||
|
@@ -43,9 +43,9 @@ type ServiceContext struct {
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
db, queryDB := mysql.NewMySQL(c.Mysql.DataSource, c.Mysql.MaxOpenConn, c.Mysql.MaxIdleConn)
|
||||
casbinEnforcer := casbinx.NewCasbin(db)
|
||||
redisClient := redisx.NewRedis(c.Redis.Host, c.Redis.Pass, c.Redis.DB)
|
||||
db, queryDB := mysql.NewMySQL(c.Mysql.DataSource, c.Mysql.MaxOpenConn, c.Mysql.MaxIdleConn, redisClient)
|
||||
casbinEnforcer := casbinx.NewCasbin(db)
|
||||
session := redis_session.NewRedisSession(redisClient)
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
|
@@ -84,6 +84,9 @@ func main() {
|
||||
// 将非默认字段名的字段定义为自动时间戳和软删除字段;
|
||||
// 自动时间戳默认字段名为:`updated_at`、`created_at, 表字段数据类型为: INT 或 DATETIME
|
||||
// 软删除默认字段名为:`deleted_at`, 表字段数据类型为: DATETIME
|
||||
idField := gen.FieldGORMTag("id", func(tag field.GormTag) field.GormTag {
|
||||
return tag.Append("primary_key")
|
||||
})
|
||||
autoUpdateTimeField := gen.FieldGORMTag("updated_at", func(tag field.GormTag) field.GormTag {
|
||||
return tag.Append("autoUpdateTime")
|
||||
})
|
||||
@@ -93,7 +96,7 @@ func main() {
|
||||
softDeleteField := gen.FieldType("delete_at", "gorm.DeletedAt")
|
||||
versionField := gen.FieldType("version", "optimisticlock.Version")
|
||||
// 模型自定义选项组
|
||||
fieldOpts := []gen.ModelOpt{jsonField, autoUpdateTimeField, autoCreateTimeField, softDeleteField, versionField}
|
||||
fieldOpts := []gen.ModelOpt{jsonField, idField, autoUpdateTimeField, autoCreateTimeField, softDeleteField, versionField}
|
||||
|
||||
// 创建全部模型文件, 并覆盖前面创建的同名模型
|
||||
allModel := g.GenerateAllTable(fieldOpts...)
|
||||
|
@@ -14,19 +14,19 @@ const TableNameScaAuthMenu = "sca_auth_menu"
|
||||
|
||||
// ScaAuthMenu mapped from table <sca_auth_menu>
|
||||
type ScaAuthMenu struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID" json:"id,string"` // 主键ID
|
||||
MenuName string `gorm:"column:menu_name;type:varchar(64);comment:名称" json:"menu_name"` // 名称
|
||||
ParentID int64 `gorm:"column:parent_id;type:bigint;comment:父ID" json:"parent_id"` // 父ID
|
||||
Type int64 `gorm:"column:type;type:tinyint;comment:类型" json:"type"` // 类型
|
||||
Path string `gorm:"column:path;type:varchar(30);comment:路径" json:"path"` // 路径
|
||||
Status int64 `gorm:"column:status;type:tinyint;comment:状态 0 启用 1 停用" json:"status"` // 状态 0 启用 1 停用
|
||||
Icon string `gorm:"column:icon;type:varchar(128);comment:图标" json:"icon"` // 图标
|
||||
MenuKey string `gorm:"column:menu_key;type:varchar(64);comment:关键字" json:"menu_key"` // 关键字
|
||||
Order_ int64 `gorm:"column:order;type:int;comment:排序" json:"order"` // 排序
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
Remark string `gorm:"column:remark;type:varchar(255);comment:备注 描述" json:"remark"` // 备注 描述
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID;primary_key" json:"id,string"` // 主键ID
|
||||
MenuName string `gorm:"column:menu_name;type:varchar(64);comment:名称" json:"menu_name"` // 名称
|
||||
ParentID int64 `gorm:"column:parent_id;type:bigint;comment:父ID" json:"parent_id"` // 父ID
|
||||
Type int64 `gorm:"column:type;type:tinyint;comment:类型" json:"type"` // 类型
|
||||
Path string `gorm:"column:path;type:varchar(30);comment:路径" json:"path"` // 路径
|
||||
Status int64 `gorm:"column:status;type:tinyint;comment:状态 0 启用 1 停用" json:"status"` // 状态 0 启用 1 停用
|
||||
Icon string `gorm:"column:icon;type:varchar(128);comment:图标" json:"icon"` // 图标
|
||||
MenuKey string `gorm:"column:menu_key;type:varchar(64);comment:关键字" json:"menu_key"` // 关键字
|
||||
Order_ int64 `gorm:"column:order;type:int;comment:排序" json:"order"` // 排序
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
Remark string `gorm:"column:remark;type:varchar(255);comment:备注 描述" json:"remark"` // 备注 描述
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaAuthMenu's table name
|
||||
|
@@ -8,7 +8,7 @@ const TableNameScaAuthPermissionRule = "sca_auth_permission_rule"
|
||||
|
||||
// ScaAuthPermissionRule mapped from table <sca_auth_permission_rule>
|
||||
type ScaAuthPermissionRule struct {
|
||||
ID int64 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id,string"`
|
||||
ID int64 `gorm:"column:id;type:int;primaryKey;autoIncrement:true;primary_key" json:"id,string"`
|
||||
Ptype string `gorm:"column:ptype;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:1;index:IDX_sca_auth_permission_rule_ptype,priority:1" json:"ptype"`
|
||||
V0 string `gorm:"column:v0;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:2;index:IDX_sca_auth_permission_rule_v0,priority:1" json:"v0"`
|
||||
V1 string `gorm:"column:v1;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:3;index:IDX_sca_auth_permission_rule_v1,priority:1" json:"v1"`
|
||||
|
@@ -14,12 +14,12 @@ const TableNameScaAuthRole = "sca_auth_role"
|
||||
|
||||
// ScaAuthRole mapped from table <sca_auth_role>
|
||||
type ScaAuthRole struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID" json:"id,string"` // 主键ID
|
||||
RoleName string `gorm:"column:role_name;type:varchar(32);not null;comment:角色名称" json:"role_name"` // 角色名称
|
||||
RoleKey string `gorm:"column:role_key;type:varchar(64);not null;comment:角色关键字" json:"role_key"` // 角色关键字
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID;primary_key" json:"id,string"` // 主键ID
|
||||
RoleName string `gorm:"column:role_name;type:varchar(32);not null;comment:角色名称" json:"role_name"` // 角色名称
|
||||
RoleKey string `gorm:"column:role_key;type:varchar(64);not null;comment:角色关键字" json:"role_key"` // 角色关键字
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaAuthRole's table name
|
||||
|
@@ -14,23 +14,23 @@ const TableNameScaAuthUser = "sca_auth_user"
|
||||
|
||||
// ScaAuthUser mapped from table <sca_auth_user>
|
||||
type ScaAuthUser struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;uniqueIndex:id,priority:1;comment:自增ID" json:"id,string"` // 自增ID
|
||||
UID string `gorm:"column:uid;type:varchar(50);not null;uniqueIndex:uid,priority:1;comment:唯一ID" json:"uid"` // 唯一ID
|
||||
Username string `gorm:"column:username;type:varchar(32);comment:用户名" json:"username"` // 用户名
|
||||
Nickname string `gorm:"column:nickname;type:varchar(32);comment:昵称" json:"nickname"` // 昵称
|
||||
Email string `gorm:"column:email;type:varchar(32);comment:邮箱" json:"email"` // 邮箱
|
||||
Phone string `gorm:"column:phone;type:varchar(32);uniqueIndex:phone,priority:1;comment:电话" json:"phone"` // 电话
|
||||
Password string `gorm:"column:password;type:varchar(64);comment:密码" json:"password"` // 密码
|
||||
Gender int64 `gorm:"column:gender;type:tinyint;comment:性别" json:"gender"` // 性别
|
||||
Avatar string `gorm:"column:avatar;type:longtext;comment:头像" json:"avatar"` // 头像
|
||||
Status int64 `gorm:"column:status;type:tinyint;comment:状态 0 正常 1 封禁" json:"status"` // 状态 0 正常 1 封禁
|
||||
Introduce string `gorm:"column:introduce;type:varchar(255);comment:介绍" json:"introduce"` // 介绍
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
Blog string `gorm:"column:blog;type:varchar(30);comment:博客" json:"blog"` // 博客
|
||||
Location string `gorm:"column:location;type:varchar(50);comment:地址" json:"location"` // 地址
|
||||
Company string `gorm:"column:company;type:varchar(50);comment:公司" json:"company"` // 公司
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;uniqueIndex:id,priority:1;comment:自增ID;primary_key" json:"id,string"` // 自增ID
|
||||
UID string `gorm:"column:uid;type:varchar(50);not null;uniqueIndex:uid,priority:1;comment:唯一ID" json:"uid"` // 唯一ID
|
||||
Username string `gorm:"column:username;type:varchar(32);comment:用户名" json:"username"` // 用户名
|
||||
Nickname string `gorm:"column:nickname;type:varchar(32);comment:昵称" json:"nickname"` // 昵称
|
||||
Email string `gorm:"column:email;type:varchar(32);comment:邮箱" json:"email"` // 邮箱
|
||||
Phone string `gorm:"column:phone;type:varchar(32);uniqueIndex:phone,priority:1;comment:电话" json:"phone"` // 电话
|
||||
Password string `gorm:"column:password;type:varchar(64);comment:密码" json:"password"` // 密码
|
||||
Gender int64 `gorm:"column:gender;type:tinyint;comment:性别" json:"gender"` // 性别
|
||||
Avatar string `gorm:"column:avatar;type:longtext;comment:头像" json:"avatar"` // 头像
|
||||
Status int64 `gorm:"column:status;type:tinyint;comment:状态 0 正常 1 封禁" json:"status"` // 状态 0 正常 1 封禁
|
||||
Introduce string `gorm:"column:introduce;type:varchar(255);comment:介绍" json:"introduce"` // 介绍
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
Blog string `gorm:"column:blog;type:varchar(30);comment:博客" json:"blog"` // 博客
|
||||
Location string `gorm:"column:location;type:varchar(50);comment:地址" json:"location"` // 地址
|
||||
Company string `gorm:"column:company;type:varchar(50);comment:公司" json:"company"` // 公司
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaAuthUser's table name
|
||||
|
@@ -14,23 +14,23 @@ const TableNameScaAuthUserDevice = "sca_auth_user_device"
|
||||
|
||||
// ScaAuthUserDevice mapped from table <sca_auth_user_device>
|
||||
type ScaAuthUserDevice struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID" json:"id,string"` // 主键ID
|
||||
UserID string `gorm:"column:user_id;type:varchar(20);not null;comment:用户ID" json:"user_id"` // 用户ID
|
||||
IP string `gorm:"column:ip;type:varchar(20);comment:登录IP" json:"ip"` // 登录IP
|
||||
Location string `gorm:"column:location;type:varchar(20);comment:地址" json:"location"` // 地址
|
||||
Agent string `gorm:"column:agent;type:varchar(255);comment:设备信息" json:"agent"` // 设备信息
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
Browser string `gorm:"column:browser;type:varchar(20);comment:浏览器" json:"browser"` // 浏览器
|
||||
OperatingSystem string `gorm:"column:operating_system;type:varchar(20);comment:操作系统" json:"operating_system"` // 操作系统
|
||||
BrowserVersion string `gorm:"column:browser_version;type:varchar(20);comment:浏览器版本" json:"browser_version"` // 浏览器版本
|
||||
Mobile int64 `gorm:"column:mobile;type:tinyint(1);comment:是否为手机 0否1是" json:"mobile"` // 是否为手机 0否1是
|
||||
Bot int64 `gorm:"column:bot;type:tinyint(1);comment:是否为bot 0否1是" json:"bot"` // 是否为bot 0否1是
|
||||
Mozilla string `gorm:"column:mozilla;type:varchar(10);comment:火狐版本" json:"mozilla"` // 火狐版本
|
||||
Platform string `gorm:"column:platform;type:varchar(20);comment:平台" json:"platform"` // 平台
|
||||
EngineName string `gorm:"column:engine_name;type:varchar(20);comment:引擎名称" json:"engine_name"` // 引擎名称
|
||||
EngineVersion string `gorm:"column:engine_version;type:varchar(20);comment:引擎版本" json:"engine_version"` // 引擎版本
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID;primary_key" json:"id,string"` // 主键ID
|
||||
UserID string `gorm:"column:user_id;type:varchar(20);not null;comment:用户ID" json:"user_id"` // 用户ID
|
||||
IP string `gorm:"column:ip;type:varchar(20);comment:登录IP" json:"ip"` // 登录IP
|
||||
Location string `gorm:"column:location;type:varchar(20);comment:地址" json:"location"` // 地址
|
||||
Agent string `gorm:"column:agent;type:varchar(255);comment:设备信息" json:"agent"` // 设备信息
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
Browser string `gorm:"column:browser;type:varchar(20);comment:浏览器" json:"browser"` // 浏览器
|
||||
OperatingSystem string `gorm:"column:operating_system;type:varchar(20);comment:操作系统" json:"operating_system"` // 操作系统
|
||||
BrowserVersion string `gorm:"column:browser_version;type:varchar(20);comment:浏览器版本" json:"browser_version"` // 浏览器版本
|
||||
Mobile int64 `gorm:"column:mobile;type:tinyint(1);comment:是否为手机 0否1是" json:"mobile"` // 是否为手机 0否1是
|
||||
Bot int64 `gorm:"column:bot;type:tinyint(1);comment:是否为bot 0否1是" json:"bot"` // 是否为bot 0否1是
|
||||
Mozilla string `gorm:"column:mozilla;type:varchar(10);comment:火狐版本" json:"mozilla"` // 火狐版本
|
||||
Platform string `gorm:"column:platform;type:varchar(20);comment:平台" json:"platform"` // 平台
|
||||
EngineName string `gorm:"column:engine_name;type:varchar(20);comment:引擎名称" json:"engine_name"` // 引擎名称
|
||||
EngineVersion string `gorm:"column:engine_version;type:varchar(20);comment:引擎版本" json:"engine_version"` // 引擎版本
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaAuthUserDevice's table name
|
||||
|
@@ -14,14 +14,14 @@ const TableNameScaAuthUserSocial = "sca_auth_user_social"
|
||||
|
||||
// ScaAuthUserSocial mapped from table <sca_auth_user_social>
|
||||
type ScaAuthUserSocial struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID" json:"id,string"` // 主键ID
|
||||
UserID string `gorm:"column:user_id;type:varchar(50);not null;comment:用户ID" json:"user_id"` // 用户ID
|
||||
OpenID string `gorm:"column:open_id;type:varchar(50);not null;comment:第三方用户的 open id" json:"open_id"` // 第三方用户的 open id
|
||||
Source string `gorm:"column:source;type:varchar(10);comment:第三方用户来源" json:"source"` // 第三方用户来源
|
||||
Status int64 `gorm:"column:status;type:bigint;comment:状态 0正常 1 封禁" json:"status"` // 状态 0正常 1 封禁
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID;primary_key" json:"id,string"` // 主键ID
|
||||
UserID string `gorm:"column:user_id;type:varchar(50);not null;comment:用户ID" json:"user_id"` // 用户ID
|
||||
OpenID string `gorm:"column:open_id;type:varchar(50);not null;comment:第三方用户的 open id" json:"open_id"` // 第三方用户的 open id
|
||||
Source string `gorm:"column:source;type:varchar(10);comment:第三方用户来源" json:"source"` // 第三方用户来源
|
||||
Status int64 `gorm:"column:status;type:bigint;comment:状态 0正常 1 封禁" json:"status"` // 状态 0正常 1 封禁
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaAuthUserSocial's table name
|
||||
|
@@ -12,11 +12,11 @@ const TableNameScaCommentLike = "sca_comment_likes"
|
||||
|
||||
// ScaCommentLike mapped from table <sca_comment_likes>
|
||||
type ScaCommentLike struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键id" json:"id,string"` // 主键id
|
||||
TopicID string `gorm:"column:topic_id;type:varchar(50);not null;comment:话题ID" json:"topic_id"` // 话题ID
|
||||
UserID string `gorm:"column:user_id;type:varchar(50);not null;comment:用户ID" json:"user_id"` // 用户ID
|
||||
CommentID int64 `gorm:"column:comment_id;type:bigint;not null;comment:评论ID" json:"comment_id"` // 评论ID
|
||||
LikeTime time.Time `gorm:"column:like_time;type:timestamp;comment:点赞时间" json:"like_time"` // 点赞时间
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键id;primary_key" json:"id,string"` // 主键id
|
||||
TopicID string `gorm:"column:topic_id;type:varchar(50);not null;comment:话题ID" json:"topic_id"` // 话题ID
|
||||
UserID string `gorm:"column:user_id;type:varchar(50);not null;comment:用户ID" json:"user_id"` // 用户ID
|
||||
CommentID int64 `gorm:"column:comment_id;type:bigint;not null;comment:评论ID" json:"comment_id"` // 评论ID
|
||||
LikeTime time.Time `gorm:"column:like_time;type:timestamp;comment:点赞时间" json:"like_time"` // 点赞时间
|
||||
}
|
||||
|
||||
// TableName ScaCommentLike's table name
|
||||
|
@@ -15,27 +15,27 @@ const TableNameScaCommentReply = "sca_comment_reply"
|
||||
|
||||
// ScaCommentReply mapped from table <sca_comment_reply>
|
||||
type ScaCommentReply struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;uniqueIndex:id,priority:1;comment:主键id" json:"id,string"` // 主键id
|
||||
UserID string `gorm:"column:user_id;type:varchar(50);not null;comment:评论用户id" json:"user_id"` // 评论用户id
|
||||
TopicID string `gorm:"column:topic_id;type:varchar(50);comment:评论话题id" json:"topic_id"` // 评论话题id
|
||||
TopicType int64 `gorm:"column:topic_type;type:tinyint;comment:话题类型" json:"topic_type"` // 话题类型
|
||||
Content string `gorm:"column:content;type:text;comment:评论内容" json:"content"` // 评论内容
|
||||
CommentType int64 `gorm:"column:comment_type;type:bigint;comment:评论类型 0评论 1 回复" json:"comment_type"` // 评论类型 0评论 1 回复
|
||||
ReplyTo int64 `gorm:"column:reply_to;type:bigint;comment:回复子评论ID" json:"reply_to"` // 回复子评论ID
|
||||
ReplyID int64 `gorm:"column:reply_id;type:bigint;comment:回复父评论Id" json:"reply_id"` // 回复父评论Id
|
||||
ReplyUser string `gorm:"column:reply_user;type:varchar(50);comment:回复人id" json:"reply_user"` // 回复人id
|
||||
Author int64 `gorm:"column:author;type:tinyint;comment:评论回复是否作者 0否 1是" json:"author"` // 评论回复是否作者 0否 1是
|
||||
Likes int64 `gorm:"column:likes;type:bigint;comment:点赞数" json:"likes"` // 点赞数
|
||||
ReplyCount int64 `gorm:"column:reply_count;type:bigint;comment:回复数量" json:"reply_count"` // 回复数量
|
||||
Browser string `gorm:"column:browser;type:varchar(50);comment:浏览器" json:"browser"` // 浏览器
|
||||
OperatingSystem string `gorm:"column:operating_system;type:varchar(50);comment:操作系统" json:"operating_system"` // 操作系统
|
||||
CommentIP string `gorm:"column:comment_ip;type:varchar(50);comment:IP地址" json:"comment_ip"` // IP地址
|
||||
Location string `gorm:"column:location;type:varchar(50);comment:地址" json:"location"` // 地址
|
||||
Agent string `gorm:"column:agent;type:varchar(255);comment:设备信息" json:"agent"` // 设备信息
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
Version optimisticlock.Version `gorm:"column:version;type:bigint;comment:版本" json:"version"` // 版本
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;uniqueIndex:id,priority:1;comment:主键id;primary_key" json:"id,string"` // 主键id
|
||||
UserID string `gorm:"column:user_id;type:varchar(50);not null;comment:评论用户id" json:"user_id"` // 评论用户id
|
||||
TopicID string `gorm:"column:topic_id;type:varchar(50);comment:评论话题id" json:"topic_id"` // 评论话题id
|
||||
TopicType int64 `gorm:"column:topic_type;type:tinyint;comment:话题类型" json:"topic_type"` // 话题类型
|
||||
Content string `gorm:"column:content;type:text;comment:评论内容" json:"content"` // 评论内容
|
||||
CommentType int64 `gorm:"column:comment_type;type:bigint;comment:评论类型 0评论 1 回复" json:"comment_type"` // 评论类型 0评论 1 回复
|
||||
ReplyTo int64 `gorm:"column:reply_to;type:bigint;comment:回复子评论ID" json:"reply_to"` // 回复子评论ID
|
||||
ReplyID int64 `gorm:"column:reply_id;type:bigint;comment:回复父评论Id" json:"reply_id"` // 回复父评论Id
|
||||
ReplyUser string `gorm:"column:reply_user;type:varchar(50);comment:回复人id" json:"reply_user"` // 回复人id
|
||||
Author int64 `gorm:"column:author;type:tinyint;comment:评论回复是否作者 0否 1是" json:"author"` // 评论回复是否作者 0否 1是
|
||||
Likes int64 `gorm:"column:likes;type:bigint;comment:点赞数" json:"likes"` // 点赞数
|
||||
ReplyCount int64 `gorm:"column:reply_count;type:bigint;comment:回复数量" json:"reply_count"` // 回复数量
|
||||
Browser string `gorm:"column:browser;type:varchar(50);comment:浏览器" json:"browser"` // 浏览器
|
||||
OperatingSystem string `gorm:"column:operating_system;type:varchar(50);comment:操作系统" json:"operating_system"` // 操作系统
|
||||
CommentIP string `gorm:"column:comment_ip;type:varchar(50);comment:IP地址" json:"comment_ip"` // IP地址
|
||||
Location string `gorm:"column:location;type:varchar(50);comment:地址" json:"location"` // 地址
|
||||
Agent string `gorm:"column:agent;type:varchar(255);comment:设备信息" json:"agent"` // 设备信息
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
Version optimisticlock.Version `gorm:"column:version;type:bigint;comment:版本" json:"version"` // 版本
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaCommentReply's table name
|
||||
|
@@ -14,7 +14,7 @@ const TableNameScaFileFolder = "sca_file_folder"
|
||||
|
||||
// ScaFileFolder mapped from table <sca_file_folder>
|
||||
type ScaFileFolder struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键" json:"id,string"` // 主键
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键;primary_key" json:"id,string"` // 主键
|
||||
FolderName string `gorm:"column:folder_name;type:varchar(512);comment:文件夹名称" json:"folder_name"` // 文件夹名称
|
||||
ParentFolderID int64 `gorm:"column:parent_folder_id;type:bigint;comment:父文件夹编号" json:"parent_folder_id"` // 父文件夹编号
|
||||
FolderAddr string `gorm:"column:folder_addr;type:varchar(1024);comment:文件夹名称" json:"folder_addr"` // 文件夹名称
|
||||
|
@@ -14,7 +14,7 @@ const TableNameScaFileInfo = "sca_file_info"
|
||||
|
||||
// ScaFileInfo mapped from table <sca_file_info>
|
||||
type ScaFileInfo struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键" json:"id,string"` // 主键
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键;primary_key" json:"id,string"` // 主键
|
||||
FileName string `gorm:"column:file_name;type:varchar(50);comment:文件名" json:"file_name"` // 文件名
|
||||
FileSize float64 `gorm:"column:file_size;type:double;comment:文件大小" json:"file_size"` // 文件大小
|
||||
FileTypeID int64 `gorm:"column:file_type_id;type:bigint;comment:文件类型编号" json:"file_type_id"` // 文件类型编号
|
||||
|
@@ -12,14 +12,14 @@ const TableNameScaFileRecycle = "sca_file_recycle"
|
||||
|
||||
// ScaFileRecycle mapped from table <sca_file_recycle>
|
||||
type ScaFileRecycle struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键" json:"id,string"` // 主键
|
||||
FileID int64 `gorm:"column:file_id;type:bigint;comment:文件编号" json:"file_id"` // 文件编号
|
||||
FolderID int64 `gorm:"column:folder_id;type:bigint;comment:文件夹编号" json:"folder_id"` // 文件夹编号
|
||||
Type int64 `gorm:"column:type;type:int;comment:类型 0 文件 1 文件夹" json:"type"` // 类型 0 文件 1 文件夹
|
||||
UserID string `gorm:"column:user_id;type:varchar(20);comment:用户编号" json:"user_id"` // 用户编号
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
OriginalPath string `gorm:"column:original_path;type:varchar(1024);comment:原始路径" json:"original_path"` // 原始路径
|
||||
FileSource int64 `gorm:"column:file_source;type:int;comment:文件来源 0 相册 1 评论" json:"file_source"` // 文件来源 0 相册 1 评论
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键;primary_key" json:"id,string"` // 主键
|
||||
FileID int64 `gorm:"column:file_id;type:bigint;comment:文件编号" json:"file_id"` // 文件编号
|
||||
FolderID int64 `gorm:"column:folder_id;type:bigint;comment:文件夹编号" json:"folder_id"` // 文件夹编号
|
||||
Type int64 `gorm:"column:type;type:int;comment:类型 0 文件 1 文件夹" json:"type"` // 类型 0 文件 1 文件夹
|
||||
UserID string `gorm:"column:user_id;type:varchar(20);comment:用户编号" json:"user_id"` // 用户编号
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
OriginalPath string `gorm:"column:original_path;type:varchar(1024);comment:原始路径" json:"original_path"` // 原始路径
|
||||
FileSource int64 `gorm:"column:file_source;type:int;comment:文件来源 0 相册 1 评论" json:"file_source"` // 文件来源 0 相册 1 评论
|
||||
}
|
||||
|
||||
// TableName ScaFileRecycle's table name
|
||||
|
@@ -14,7 +14,7 @@ const TableNameScaFileType = "sca_file_type"
|
||||
|
||||
// ScaFileType mapped from table <sca_file_type>
|
||||
type ScaFileType struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键" json:"id,string"` // 主键
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键;primary_key" json:"id,string"` // 主键
|
||||
TypeName string `gorm:"column:type_name;type:varchar(100);comment:类型名称" json:"type_name"` // 类型名称
|
||||
MimeType string `gorm:"column:mime_type;type:varchar(50);comment:MIME 类型" json:"mime_type"` // MIME 类型
|
||||
Status int64 `gorm:"column:status;type:int;comment:类型状态" json:"status"` // 类型状态
|
||||
|
@@ -14,7 +14,7 @@ const TableNameScaMessageReport = "sca_message_report"
|
||||
|
||||
// ScaMessageReport mapped from table <sca_message_report>
|
||||
type ScaMessageReport struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键" json:"id,string"` // 主键
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键;primary_key" json:"id,string"` // 主键
|
||||
UserID string `gorm:"column:user_id;type:varchar(20);comment:用户Id" json:"user_id"` // 用户Id
|
||||
Type int64 `gorm:"column:type;type:tinyint;comment:举报类型 0评论 1 相册" json:"type"` // 举报类型 0评论 1 相册
|
||||
CommentID int64 `gorm:"column:comment_id;type:bigint;comment:评论Id" json:"comment_id"` // 评论Id
|
||||
|
@@ -19,7 +19,7 @@ type ScaUserFollow struct {
|
||||
Status int64 `gorm:"column:status;type:tinyint unsigned;not null;comment:关注状态(0 未互关 1 互关)" json:"status"` // 关注状态(0 未互关 1 互关)
|
||||
CreatedAt *time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt *time.Time `gorm:"column:updated_at;type:timestamp;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id,string"`
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;primary_key" json:"id,string"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,7 @@ const TableNameScaUserLevel = "sca_user_level"
|
||||
|
||||
// ScaUserLevel mapped from table <sca_user_level>
|
||||
type ScaUserLevel struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;comment:主键" json:"id,string"` // 主键
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;comment:主键;primary_key" json:"id,string"` // 主键
|
||||
UserID string `gorm:"column:user_id;type:varchar(50);comment:用户Id" json:"user_id"` // 用户Id
|
||||
LevelType int64 `gorm:"column:level_type;type:tinyint unsigned;comment:等级类型" json:"level_type"` // 等级类型
|
||||
Level int64 `gorm:"column:level;type:int;comment:等级" json:"level"` // 等级
|
||||
|
@@ -14,15 +14,15 @@ const TableNameScaUserMessage = "sca_user_message"
|
||||
|
||||
// ScaUserMessage mapped from table <sca_user_message>
|
||||
type ScaUserMessage struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键" json:"id,string"` // 主键
|
||||
TopicID string `gorm:"column:topic_id;type:varchar(50);comment:话题Id" json:"topic_id"` // 话题Id
|
||||
FromID string `gorm:"column:from_id;type:varchar(50);comment:来自人" json:"from_id"` // 来自人
|
||||
ToID string `gorm:"column:to_id;type:varchar(50);comment:送达人" json:"to_id"` // 送达人
|
||||
Content string `gorm:"column:content;type:text;comment:消息内容" json:"content"` // 消息内容
|
||||
IsRead int64 `gorm:"column:is_read;type:tinyint;comment:是否已读" json:"is_read"` // 是否已读
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键;primary_key" json:"id,string"` // 主键
|
||||
TopicID string `gorm:"column:topic_id;type:varchar(50);comment:话题Id" json:"topic_id"` // 话题Id
|
||||
FromID string `gorm:"column:from_id;type:varchar(50);comment:来自人" json:"from_id"` // 来自人
|
||||
ToID string `gorm:"column:to_id;type:varchar(50);comment:送达人" json:"to_id"` // 送达人
|
||||
Content string `gorm:"column:content;type:text;comment:消息内容" json:"content"` // 消息内容
|
||||
IsRead int64 `gorm:"column:is_read;type:tinyint;comment:是否已读" json:"is_read"` // 是否已读
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaUserMessage's table name
|
||||
|
@@ -5,6 +5,10 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/asjdf/gorm-cache/cache"
|
||||
"github.com/asjdf/gorm-cache/config"
|
||||
"github.com/asjdf/gorm-cache/storage"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
@@ -12,7 +16,7 @@ import (
|
||||
"schisandra-album-cloud-microservices/app/core/api/repository/mysql/query"
|
||||
)
|
||||
|
||||
func NewMySQL(url string, maxOpenConn int, maxIdleConn int) (*gorm.DB, *query.Query) {
|
||||
func NewMySQL(url string, maxOpenConn int, maxIdleConn int, client *redis.Client) (*gorm.DB, *query.Query) {
|
||||
db, err := gorm.Open(mysql.Open(url), &gorm.Config{
|
||||
SkipDefaultTransaction: true,
|
||||
PrepareStmt: true,
|
||||
@@ -36,5 +40,27 @@ func NewMySQL(url string, maxOpenConn int, maxIdleConn int) (*gorm.DB, *query.Qu
|
||||
sqlDB.SetMaxOpenConns(maxOpenConn)
|
||||
sqlDB.SetMaxIdleConns(maxIdleConn)
|
||||
useDB := query.Use(db)
|
||||
// cache
|
||||
gormCache, err := cache.NewGorm2Cache(&config.CacheConfig{
|
||||
CacheLevel: config.CacheLevelAll,
|
||||
CacheStorage: storage.NewRedis(&storage.RedisStoreConfig{
|
||||
KeyPrefix: "cache",
|
||||
Client: client,
|
||||
}),
|
||||
InvalidateWhenUpdate: true, // when you create/update/delete objects, invalidate cache
|
||||
CacheTTL: 10000, // 5000 ms
|
||||
CacheMaxItemCnt: 0, // if length of objects retrieved one single time
|
||||
AsyncWrite: true, // async write to cache
|
||||
DebugMode: true,
|
||||
DisableCachePenetrationProtect: true, // disable cache penetration protect
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = db.Use(gormCache)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return db, useDB
|
||||
}
|
||||
|
Reference in New Issue
Block a user