master
李光春 2 years ago
parent 0565ef6626
commit 259ee637e0

@ -1,6 +1,7 @@
package golog package golog
import ( import (
"go.dtapp.net/goip"
"gorm.io/datatypes" "gorm.io/datatypes"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -55,3 +56,10 @@ func (a *api) Record(content ApiPostgresqlLog) int64 {
func (a *api) Query() *gorm.DB { func (a *api) Query() *gorm.DB {
return a.db.Table(a.tableName) return a.db.Table(a.tableName)
} }
// 配置
func (a *api) configOutsideIp() {
go func() {
a.insideIp = goip.GetOutsideIp()
}()
}

@ -22,9 +22,9 @@ func (a *App) InitClientApi() {
} }
a.Api.db = a.Pgsql a.Api.db = a.Pgsql
a.Api.tableName = a.TableName a.Api.tableName = a.TableName
a.Api.outsideIp = goip.GetOutsideIp()
a.Api.insideIp = goip.GetInsideIp() a.Api.insideIp = goip.GetInsideIp()
a.Api.AutoMigrate() a.Api.AutoMigrate()
a.Api.configOutsideIp()
} }
// InitClientGin 框架实例化 // InitClientGin 框架实例化
@ -37,7 +37,7 @@ func (a *App) InitClientGin() {
} }
a.Gin.db = a.Pgsql a.Gin.db = a.Pgsql
a.Gin.tableName = a.TableName a.Gin.tableName = a.TableName
a.Gin.outsideIp = goip.GetOutsideIp()
a.Gin.insideIp = goip.GetInsideIp() a.Gin.insideIp = goip.GetInsideIp()
a.Gin.AutoMigrate() a.Gin.AutoMigrate()
a.Gin.configOutsideIp()
} }

@ -18,8 +18,9 @@ func NewClientGin(db *gorm.DB, tableName string) *Client {
if tableName == "" { if tableName == "" {
panic("表名不能为空") panic("表名不能为空")
} }
client := &Client{Gin: gin{db: db, tableName: tableName, outsideIp: goip.GetOutsideIp(), insideIp: goip.GetInsideIp()}} client := &Client{Gin: gin{db: db, tableName: tableName, insideIp: goip.GetInsideIp()}}
client.Gin.AutoMigrate() client.Gin.AutoMigrate()
client.Gin.configOutsideIp()
return client return client
} }
@ -31,7 +32,8 @@ func NewClientApi(db *gorm.DB, tableName string) *Client {
if tableName == "" { if tableName == "" {
panic("表名不能为空") panic("表名不能为空")
} }
client := &Client{Api: api{db: db, tableName: tableName, outsideIp: goip.GetOutsideIp(), insideIp: goip.GetInsideIp()}} client := &Client{Api: api{db: db, tableName: tableName, insideIp: goip.GetInsideIp()}}
client.Api.AutoMigrate() client.Api.AutoMigrate()
client.Api.configOutsideIp()
return client return client
} }

@ -1,6 +1,7 @@
package golog package golog
import ( import (
"go.dtapp.net/goip"
"gorm.io/datatypes" "gorm.io/datatypes"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -66,3 +67,10 @@ func (g *gin) Record(content GinPostgresqlLog) int64 {
func (g *gin) Query() *gorm.DB { func (g *gin) Query() *gorm.DB {
return g.db.Table(g.tableName) return g.db.Table(g.tableName)
} }
// 配置
func (g *gin) configOutsideIp() {
go func() {
g.insideIp = goip.GetOutsideIp()
}()
}

Loading…
Cancel
Save