优化
continuous-integration/drone/push Build is passing Details

master v1.0.10
李光春 2 years ago
parent 0ff9f0fc4b
commit cc1635746e

@ -3,6 +3,7 @@ package golog
import ( import (
"gorm.io/datatypes" "gorm.io/datatypes"
"gorm.io/gorm" "gorm.io/gorm"
"log"
) )
// 接口定义 // 接口定义
@ -35,24 +36,28 @@ type ApiPostgresqlLog struct {
} }
// AutoMigrate 自动迁移 // AutoMigrate 自动迁移
func (a *api) AutoMigrate() { func (p *api) AutoMigrate() {
err := a.db.Table(a.tableName).AutoMigrate(&ApiPostgresqlLog{}) err := p.db.Table(p.tableName).AutoMigrate(&ApiPostgresqlLog{})
if err != nil { if err != nil {
panic("创建表失败:" + err.Error()) panic("创建表失败:" + err.Error())
} }
} }
// Record 记录日志 // Record 记录日志
func (a *api) Record(content ApiPostgresqlLog) int64 { func (p *api) Record(content ApiPostgresqlLog) *gorm.DB {
content.SystemHostName = a.hostname content.SystemHostName = p.hostname
if content.SystemInsideIp == "" { if content.SystemInsideIp == "" {
content.SystemInsideIp = a.insideIp content.SystemInsideIp = p.insideIp
} }
content.GoVersion = a.goVersion content.GoVersion = p.goVersion
return a.db.Table(a.tableName).Create(&content).RowsAffected resp := p.db.Table(p.tableName).Create(&content)
if resp.RowsAffected == 0 {
log.Println("api", resp.Error)
}
return resp
} }
// Query 查询 // Query 查询
func (a *api) Query() *gorm.DB { func (p *api) Query() *gorm.DB {
return a.db.Table(a.tableName) return p.db.Table(p.tableName)
} }

@ -3,6 +3,7 @@ package golog
import ( import (
"gorm.io/datatypes" "gorm.io/datatypes"
"gorm.io/gorm" "gorm.io/gorm"
"log"
) )
// 框架定义 // 框架定义
@ -46,24 +47,28 @@ type GinPostgresqlLog struct {
} }
// AutoMigrate 自动迁移 // AutoMigrate 自动迁移
func (g *gin) AutoMigrate() { func (p *gin) AutoMigrate() {
err := g.db.Table(g.tableName).AutoMigrate(&GinPostgresqlLog{}) err := p.db.Table(p.tableName).AutoMigrate(&GinPostgresqlLog{})
if err != nil { if err != nil {
panic("创建表失败:" + err.Error()) panic("创建表失败:" + err.Error())
} }
} }
// Record 记录日志 // Record 记录日志
func (g *gin) Record(content GinPostgresqlLog) int64 { func (p *gin) Record(content GinPostgresqlLog) *gorm.DB {
content.SystemHostName = g.hostname content.SystemHostName = p.hostname
if content.SystemInsideIp == "" { if content.SystemInsideIp == "" {
content.SystemInsideIp = g.insideIp content.SystemInsideIp = p.insideIp
} }
content.GoVersion = g.goVersion content.GoVersion = p.goVersion
return g.db.Table(g.tableName).Create(&content).RowsAffected resp := p.db.Table(p.tableName).Create(&content)
if resp.RowsAffected == 0 {
log.Println("gin", resp.Error)
}
return resp
} }
// Query 查询 // Query 查询
func (g *gin) Query() *gorm.DB { func (p *gin) Query() *gorm.DB {
return g.db.Table(g.tableName) return p.db.Table(p.tableName)
} }

@ -1,3 +1,3 @@
package golog package golog
const Version = "1.0.9" const Version = "1.0.10"

Loading…
Cancel
Save