diff --git a/api.go b/api.go index e8b2d1d..0a8027c 100644 --- a/api.go +++ b/api.go @@ -3,6 +3,7 @@ package golog import ( "gorm.io/datatypes" "gorm.io/gorm" + "log" ) // 接口定义 @@ -35,24 +36,28 @@ type ApiPostgresqlLog struct { } // AutoMigrate 自动迁移 -func (a *api) AutoMigrate() { - err := a.db.Table(a.tableName).AutoMigrate(&ApiPostgresqlLog{}) +func (p *api) AutoMigrate() { + err := p.db.Table(p.tableName).AutoMigrate(&ApiPostgresqlLog{}) if err != nil { panic("创建表失败:" + err.Error()) } } // Record 记录日志 -func (a *api) Record(content ApiPostgresqlLog) int64 { - content.SystemHostName = a.hostname +func (p *api) Record(content ApiPostgresqlLog) *gorm.DB { + content.SystemHostName = p.hostname if content.SystemInsideIp == "" { - content.SystemInsideIp = a.insideIp + content.SystemInsideIp = p.insideIp } - content.GoVersion = a.goVersion - return a.db.Table(a.tableName).Create(&content).RowsAffected + content.GoVersion = p.goVersion + resp := p.db.Table(p.tableName).Create(&content) + if resp.RowsAffected == 0 { + log.Println("api:", resp.Error) + } + return resp } // Query 查询 -func (a *api) Query() *gorm.DB { - return a.db.Table(a.tableName) +func (p *api) Query() *gorm.DB { + return p.db.Table(p.tableName) } diff --git a/gin.go b/gin.go index e221cbc..f25c25f 100644 --- a/gin.go +++ b/gin.go @@ -3,6 +3,7 @@ package golog import ( "gorm.io/datatypes" "gorm.io/gorm" + "log" ) // 框架定义 @@ -46,24 +47,28 @@ type GinPostgresqlLog struct { } // AutoMigrate 自动迁移 -func (g *gin) AutoMigrate() { - err := g.db.Table(g.tableName).AutoMigrate(&GinPostgresqlLog{}) +func (p *gin) AutoMigrate() { + err := p.db.Table(p.tableName).AutoMigrate(&GinPostgresqlLog{}) if err != nil { panic("创建表失败:" + err.Error()) } } // Record 记录日志 -func (g *gin) Record(content GinPostgresqlLog) int64 { - content.SystemHostName = g.hostname +func (p *gin) Record(content GinPostgresqlLog) *gorm.DB { + content.SystemHostName = p.hostname if content.SystemInsideIp == "" { - content.SystemInsideIp = g.insideIp + content.SystemInsideIp = p.insideIp } - content.GoVersion = g.goVersion - return g.db.Table(g.tableName).Create(&content).RowsAffected + content.GoVersion = p.goVersion + resp := p.db.Table(p.tableName).Create(&content) + if resp.RowsAffected == 0 { + log.Println("gin:", resp.Error) + } + return resp } // Query 查询 -func (g *gin) Query() *gorm.DB { - return g.db.Table(g.tableName) +func (p *gin) Query() *gorm.DB { + return p.db.Table(p.tableName) } diff --git a/version.go b/version.go index 88054fd..b8d2157 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package golog -const Version = "1.0.9" +const Version = "1.0.10"