优化
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 (
"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)
}

@ -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)
}

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

Loading…
Cancel
Save