|
|
|
@ -10,8 +10,6 @@ import (
|
|
|
|
|
"go.dtapp.net/gotrace_id"
|
|
|
|
|
"go.dtapp.net/gourl"
|
|
|
|
|
"gorm.io/datatypes"
|
|
|
|
|
"os"
|
|
|
|
|
"runtime"
|
|
|
|
|
"unicode/utf8"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -41,13 +39,17 @@ func NewApiGormClient(config *ApiGormClientConfig) (*ApiClient, error) {
|
|
|
|
|
config.CurrentIp = goip.GetOutsideIp(ctx)
|
|
|
|
|
}
|
|
|
|
|
if config.CurrentIp != "" && config.CurrentIp != "0.0.0.0" {
|
|
|
|
|
c.currentIp = config.CurrentIp
|
|
|
|
|
c.config.systemOutsideIp = config.CurrentIp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if c.config.systemOutsideIp == "" {
|
|
|
|
|
return nil, currentIpNoConfig
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client, tableName := config.GormClientFun()
|
|
|
|
|
|
|
|
|
|
if client == nil || client.Db == nil {
|
|
|
|
|
return nil, errors.New("没有设置驱动")
|
|
|
|
|
return nil, gormClientFunNoConfig
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.gormClient = client
|
|
|
|
@ -62,11 +64,8 @@ func NewApiGormClient(config *ApiGormClientConfig) (*ApiClient, error) {
|
|
|
|
|
return nil, errors.New("创建表失败:" + err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hostname, _ := os.Hostname()
|
|
|
|
|
|
|
|
|
|
c.gormConfig.hostname = hostname
|
|
|
|
|
c.gormConfig.insideIp = goip.GetInsideIp(ctx)
|
|
|
|
|
c.gormConfig.goVersion = runtime.Version()
|
|
|
|
|
// 配置信息
|
|
|
|
|
c.setConfig(ctx)
|
|
|
|
|
|
|
|
|
|
return c, nil
|
|
|
|
|
}
|
|
|
|
@ -94,16 +93,13 @@ func (c *ApiClient) gormRecord(ctx context.Context, data apiPostgresqlLogString)
|
|
|
|
|
data.ResponseBody = ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.SystemHostName = c.gormConfig.hostname
|
|
|
|
|
data.SystemInsideIp = c.gormConfig.insideIp
|
|
|
|
|
data.GoVersion = c.gormConfig.goVersion
|
|
|
|
|
|
|
|
|
|
data.SystemHostName = c.config.systemHostName
|
|
|
|
|
data.SystemInsideIp = c.config.systemInsideIp
|
|
|
|
|
data.GoVersion = c.config.goVersion
|
|
|
|
|
data.TraceId = gotrace_id.GetTraceIdContext(ctx)
|
|
|
|
|
|
|
|
|
|
data.RequestIp = c.currentIp
|
|
|
|
|
|
|
|
|
|
data.SystemOs = c.config.os
|
|
|
|
|
data.SystemArch = c.config.arch
|
|
|
|
|
data.RequestIp = c.config.systemOutsideIp
|
|
|
|
|
data.SystemOs = c.config.systemOs
|
|
|
|
|
data.SystemArch = c.config.systemArch
|
|
|
|
|
|
|
|
|
|
if c.config.jsonStatus {
|
|
|
|
|
err = c.gormClient.Db.Table(c.gormConfig.tableName).Create(&apiPostgresqlLogJson{
|
|
|
|
|