diff --git a/api.go b/api.go index 357bf4a..b32de42 100644 --- a/api.go +++ b/api.go @@ -1,6 +1,7 @@ package golog import ( + "go.dtapp.net/goip" "gorm.io/datatypes" "gorm.io/gorm" ) @@ -55,3 +56,10 @@ func (a *api) Record(content ApiPostgresqlLog) int64 { func (a *api) Query() *gorm.DB { return a.db.Table(a.tableName) } + +// 配置 +func (a *api) configOutsideIp() { + go func() { + a.insideIp = goip.GetOutsideIp() + }() +} diff --git a/app.go b/app.go index 65d6dcc..a69f7ba 100644 --- a/app.go +++ b/app.go @@ -22,9 +22,9 @@ func (a *App) InitClientApi() { } a.Api.db = a.Pgsql a.Api.tableName = a.TableName - a.Api.outsideIp = goip.GetOutsideIp() a.Api.insideIp = goip.GetInsideIp() a.Api.AutoMigrate() + a.Api.configOutsideIp() } // InitClientGin 框架实例化 @@ -37,7 +37,7 @@ func (a *App) InitClientGin() { } a.Gin.db = a.Pgsql a.Gin.tableName = a.TableName - a.Gin.outsideIp = goip.GetOutsideIp() a.Gin.insideIp = goip.GetInsideIp() a.Gin.AutoMigrate() + a.Gin.configOutsideIp() } diff --git a/client.go b/client.go index 85cc885..497a7af 100644 --- a/client.go +++ b/client.go @@ -18,8 +18,9 @@ func NewClientGin(db *gorm.DB, tableName string) *Client { if tableName == "" { 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.configOutsideIp() return client } @@ -31,7 +32,8 @@ func NewClientApi(db *gorm.DB, tableName string) *Client { if tableName == "" { 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.configOutsideIp() return client } diff --git a/gin.go b/gin.go index b056e1e..b23d215 100644 --- a/gin.go +++ b/gin.go @@ -1,6 +1,7 @@ package golog import ( + "go.dtapp.net/goip" "gorm.io/datatypes" "gorm.io/gorm" ) @@ -66,3 +67,10 @@ func (g *gin) Record(content GinPostgresqlLog) int64 { func (g *gin) Query() *gorm.DB { return g.db.Table(g.tableName) } + +// 配置 +func (g *gin) configOutsideIp() { + go func() { + g.insideIp = goip.GetOutsideIp() + }() +}