- update db

master v1.0.90
李光春 2 years ago
parent 592b43fc26
commit a7e10e9661

@ -38,7 +38,7 @@ type apiPostgresqlLog struct {
// 创建模型 // 创建模型
func (c *ApiClient) gormAutoMigrate(ctx context.Context) { func (c *ApiClient) gormAutoMigrate(ctx context.Context) {
err := c.gormClient.Db.Table(c.gormConfig.tableName).AutoMigrate(&apiPostgresqlLog{}) err := c.gormClient.GetDb().Table(c.gormConfig.tableName).AutoMigrate(&apiPostgresqlLog{})
if err != nil { if err != nil {
c.zapLog.WithTraceId(ctx).Sugar().Errorf("创建模型:%s", err) c.zapLog.WithTraceId(ctx).Sugar().Errorf("创建模型:%s", err)
} }
@ -59,7 +59,7 @@ func (c *ApiClient) gormRecord(ctx context.Context, data apiPostgresqlLog) (err
data.SystemOs = c.config.systemOs //【系统】系统类型 data.SystemOs = c.config.systemOs //【系统】系统类型
data.SystemArch = c.config.systemArch //【系统】系统架构 data.SystemArch = c.config.systemArch //【系统】系统架构
err = c.gormClient.Db.Table(c.gormConfig.tableName).Create(&data).Error err = c.gormClient.GetDb().Table(c.gormConfig.tableName).Create(&data).Error
if err != nil { if err != nil {
c.zapLog.WithTraceId(ctx).Sugar().Errorf("记录日志失败:%s", err) c.zapLog.WithTraceId(ctx).Sugar().Errorf("记录日志失败:%s", err)
} }
@ -68,7 +68,7 @@ func (c *ApiClient) gormRecord(ctx context.Context, data apiPostgresqlLog) (err
// GormDelete 删除 // GormDelete 删除
func (c *ApiClient) GormDelete(ctx context.Context, hour int64) error { func (c *ApiClient) GormDelete(ctx context.Context, hour int64) error {
return c.gormClient.Db.Table(c.gormConfig.tableName).Where("request_time < ?", gotime.Current().BeforeHour(hour).Format()).Delete(&apiPostgresqlLog{}).Error return c.gormClient.GetDb().Table(c.gormConfig.tableName).Where("request_time < ?", gotime.Current().BeforeHour(hour).Format()).Delete(&apiPostgresqlLog{}).Error
} }
// 中间件 // 中间件

@ -49,7 +49,7 @@ func (c *ApiClient) mongoCreateCollection(ctx context.Context) {
// 创建索引 // 创建索引
func (c *ApiClient) mongoCreateIndexes(ctx context.Context) { func (c *ApiClient) mongoCreateIndexes(ctx context.Context) {
indexes, err := c.mongoClient.Database(c.mongoConfig.databaseName).Collection(c.mongoConfig.collectionName).CreateManyIndexes(ctx, []mongo.IndexModel{ _, err := c.mongoClient.Database(c.mongoConfig.databaseName).Collection(c.mongoConfig.collectionName).CreateManyIndexes(ctx, []mongo.IndexModel{
{ {
Keys: bson.D{{ Keys: bson.D{{
Key: "log_time", Key: "log_time",
@ -59,7 +59,6 @@ func (c *ApiClient) mongoCreateIndexes(ctx context.Context) {
if err != nil { if err != nil {
c.zapLog.WithTraceId(ctx).Sugar().Errorf("创建索引:%s", err) c.zapLog.WithTraceId(ctx).Sugar().Errorf("创建索引:%s", err)
} }
c.zapLog.WithTraceId(ctx).Sugar().Infof("创建索引:%s", indexes)
} }
// MongoDelete 删除 // MongoDelete 删除

@ -1,5 +1,5 @@
package golog package golog
const ( const (
Version = "1.0.89" Version = "1.0.90"
) )

@ -46,7 +46,7 @@ type ginPostgresqlLog struct {
// 创建模型 // 创建模型
func (c *GinClient) gormAutoMigrate(ctx context.Context) { func (c *GinClient) gormAutoMigrate(ctx context.Context) {
err := c.gormClient.Db.Table(c.gormConfig.tableName).AutoMigrate(&ginPostgresqlLog{}) err := c.gormClient.GetDb().Table(c.gormConfig.tableName).AutoMigrate(&ginPostgresqlLog{})
if err != nil { if err != nil {
c.zapLog.WithTraceId(ctx).Sugar().Errorf("创建模型:%s", err) c.zapLog.WithTraceId(ctx).Sugar().Errorf("创建模型:%s", err)
} }
@ -62,7 +62,7 @@ func (c *GinClient) gormRecord(data ginPostgresqlLog) (err error) {
data.SystemOs = c.config.systemOs //【系统】系统类型 data.SystemOs = c.config.systemOs //【系统】系统类型
data.SystemArch = c.config.systemArch //【系统】系统架构 data.SystemArch = c.config.systemArch //【系统】系统架构
err = c.gormClient.Db.Table(c.gormConfig.tableName).Create(&data).Error err = c.gormClient.GetDb().Table(c.gormConfig.tableName).Create(&data).Error
if err != nil { if err != nil {
c.zapLog.WithTraceIdStr(data.TraceId).Sugar().Errorf("记录日志失败:%s", err) c.zapLog.WithTraceIdStr(data.TraceId).Sugar().Errorf("记录日志失败:%s", err)
} }
@ -182,5 +182,5 @@ func (c *GinClient) gormRecordXml(ginCtx *gin.Context, traceId string, requestTi
// GormDelete 删除 // GormDelete 删除
func (c *GinClient) GormDelete(ctx context.Context, hour int64) error { func (c *GinClient) GormDelete(ctx context.Context, hour int64) error {
return c.gormClient.Db.Table(c.gormConfig.tableName).Where("request_time < ?", gotime.Current().BeforeHour(hour).Format()).Delete(&ginPostgresqlLog{}).Error return c.gormClient.GetDb().Table(c.gormConfig.tableName).Where("request_time < ?", gotime.Current().BeforeHour(hour).Format()).Delete(&ginPostgresqlLog{}).Error
} }

@ -67,7 +67,7 @@ func (c *GinClient) mongoCreateCollection(ctx context.Context) {
// 创建索引 // 创建索引
func (c *GinClient) mongoCreateIndexes(ctx context.Context) { func (c *GinClient) mongoCreateIndexes(ctx context.Context) {
indexes, err := c.mongoClient.Database(c.mongoConfig.databaseName).Collection(c.mongoConfig.collectionName).CreateManyIndexes(ctx, []mongo.IndexModel{ _, err := c.mongoClient.Database(c.mongoConfig.databaseName).Collection(c.mongoConfig.collectionName).CreateManyIndexes(ctx, []mongo.IndexModel{
{ {
Keys: bson.D{{ Keys: bson.D{{
Key: "trace_id", Key: "trace_id",
@ -148,7 +148,6 @@ func (c *GinClient) mongoCreateIndexes(ctx context.Context) {
if err != nil { if err != nil {
c.zapLog.WithTraceId(ctx).Sugar().Errorf("创建索引:%s", err) c.zapLog.WithTraceId(ctx).Sugar().Errorf("创建索引:%s", err)
} }
c.zapLog.WithTraceId(ctx).Sugar().Infof("创建索引:%s", indexes)
} }
// MongoDelete 删除 // MongoDelete 删除

Loading…
Cancel
Save