- update gin

master v1.0.65
李光春 2 years ago
parent 6d83b387ca
commit ee6dd7c3ba

@ -1,5 +1,5 @@
package golog
const (
Version = "1.0.64"
Version = "1.0.65"
)

@ -198,10 +198,6 @@ func (c *GinClient) Middleware() gin.HandlerFunc {
// 判断是否有内容
if len(data) > 0 {
err := json.Unmarshal(data, &jsonBody)
if len(jsonBody) <= 0 {
dataJson = false
}
if err != nil {
dataJson = false
}

@ -12,7 +12,6 @@ import (
"go.dtapp.net/gotime"
"go.dtapp.net/gotrace_id"
"go.dtapp.net/gourl"
"go.dtapp.net/goxml"
"gorm.io/datatypes"
"gorm.io/gorm"
"io/ioutil"
@ -223,7 +222,7 @@ func (c *GinClient) gormRecordXml(ginCtx *gin.Context, traceId string, requestTi
}
if len(requestBody) > 0 {
data.RequestContent = dorm.JsonEncodeNoError(goxml.XmlDecode(requestBody)) //【请求】请求内容
data.RequestContent = dorm.XmlEncodeNoError(dorm.XmlDecodeNoError([]byte(requestBody))) //【请求】请求内容
} else {
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.gormRecordXml.len]%s %s", data.RequestUri, requestBody)
}
@ -233,10 +232,10 @@ func (c *GinClient) gormRecordXml(ginCtx *gin.Context, traceId string, requestTi
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordXml]%s", err)
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordXml.string]%s", requestBody)
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordXml.value]%+v", requestBody)
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordXml.XmlDecode.string]%s", goxml.XmlDecode(requestBody))
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordXml.XmlDecode.value]%+v", goxml.XmlDecode(requestBody))
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordXml.JsonEncodeNoError.string]%s", dorm.JsonEncodeNoError(goxml.XmlDecode(requestBody)))
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordXml.JsonEncodeNoError.value]%+v", dorm.JsonEncodeNoError(goxml.XmlDecode(requestBody)))
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordXml.XmlDecodeNoError.string]%s", dorm.XmlDecodeNoError([]byte(requestBody)))
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordXml.XmlDecodeNoError.value]%+v", dorm.XmlDecodeNoError([]byte(requestBody)))
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordXml.XmlEncodeNoError.string]%s", dorm.XmlEncodeNoError(dorm.XmlDecodeNoError([]byte(requestBody))))
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordXml.XmlEncodeNoError.value]%+v", dorm.XmlEncodeNoError(dorm.XmlDecodeNoError([]byte(requestBody))))
}
}
@ -281,35 +280,16 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
var dataJson = true
// 解析请求内容
var xmlBody map[string]string
var jsonBody map[string]interface{}
// 判断是否有内容
if len(data) > 0 {
err := json.Unmarshal(data, &jsonBody)
if len(jsonBody) <= 0 {
dataJson = false
xmlBody = goxml.XmlDecode(string(data))
}
if c.logDebug {
c.zapLog.WithLogger().Sugar().Infof("[golog.gin.GormMiddleware.len(jsonBody)] %v", len(jsonBody))
}
if err != nil {
if c.logDebug {
c.zapLog.WithLogger().Sugar().Infof("[golog.gin.GormMiddleware.json.Unmarshal] %s %s", jsonBody, err)
}
dataJson = false
xmlBody = goxml.XmlDecode(string(data))
}
}
if c.logDebug {
c.zapLog.WithLogger().Sugar().Infof("[golog.gin.GormMiddleware.xmlBody] %s", xmlBody)
c.zapLog.WithLogger().Sugar().Infof("[golog.gin.GormMiddleware.jsonBody] %s", jsonBody)
}
clientIp := gorequest.ClientIp(ginCtx.Request)
requestClientIpCountry, requestClientIpRegion, requestClientIpProvince, requestClientIpCity, requestClientIpIsp := "", "", "", "", ""
@ -337,21 +317,11 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
var traceId = gotrace_id.GetGinTraceId(ginCtx)
if dataJson {
if c.logDebug {
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.GormMiddleware.gormRecord.json.request_body]%s", jsonBody)
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.GormMiddleware.gormRecord.json.request_body]%s", dorm.JsonEncodeNoError(jsonBody))
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.GormMiddleware.gormRecord.json.request_body]%s", datatypes.JSON(dorm.JsonEncodeNoError(jsonBody)))
}
if c.logDebug {
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.GormMiddleware]准备使用{gormRecordJson}保存数据:%s", data)
}
c.gormRecordJson(ginCtx, traceId, requestTime, string(data), responseCode, responseBody, startTime, endTime, clientIp, requestClientIpCountry, requestClientIpRegion, requestClientIpProvince, requestClientIpCity, requestClientIpIsp)
} else {
if c.logDebug {
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.GormMiddleware.gormRecord.xml.request_body]%s", xmlBody)
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.GormMiddleware.gormRecord.xml.request_body]%s", dorm.JsonEncodeNoError(xmlBody))
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.GormMiddleware.gormRecord.xml.request_body]%s", datatypes.JSON(dorm.JsonEncodeNoError(xmlBody)))
}
if c.logDebug {
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.GormMiddleware]准备使用{gormRecordXml}保存数据:%s", data)
}

@ -12,7 +12,6 @@ import (
"go.dtapp.net/gotime"
"go.dtapp.net/gotrace_id"
"go.dtapp.net/gourl"
"go.dtapp.net/goxml"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
@ -300,7 +299,7 @@ func (c *GinClient) mongoRecordXml(ginCtx *gin.Context, traceId string, requestT
}
if len(requestBody) > 0 {
data.RequestBody = goxml.XmlDecode(requestBody) //【请求】请求主体
data.RequestBody = dorm.XmlDecodeNoError([]byte(requestBody)) //【请求】请求主体
} else {
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.mongoRecordXml.len]%s %s", data.RequestUri, requestBody)
}
@ -352,35 +351,16 @@ func (c *GinClient) MongoMiddleware() gin.HandlerFunc {
var dataJson = true
// 解析请求内容
var xmlBody map[string]string
var jsonBody map[string]interface{}
// 判断是否有内容
if len(data) > 0 {
err := json.Unmarshal(data, &jsonBody)
if len(jsonBody) <= 0 {
dataJson = false
xmlBody = goxml.XmlDecode(string(data))
}
if c.logDebug {
c.zapLog.WithLogger().Sugar().Infof("[golog.gin.MongoMiddleware.len(jsonBody)] %v", len(jsonBody))
}
if err != nil {
if c.logDebug {
c.zapLog.WithLogger().Sugar().Infof("[golog.gin.MongoMiddleware.json.Unmarshal] %s %s", jsonBody, err)
}
dataJson = false
xmlBody = goxml.XmlDecode(string(data))
}
}
if c.logDebug {
c.zapLog.WithLogger().Sugar().Infof("[golog.MongoMiddleware.xmlBody] %s", xmlBody)
c.zapLog.WithLogger().Sugar().Infof("[golog.MongoMiddleware.jsonBody] %s", jsonBody)
}
clientIp := gorequest.ClientIp(ginCtx.Request)
requestClientIpCountry, requestClientIpRegion, requestClientIpProvince, requestClientIpCity, requestClientIpIsp := "", "", "", "", ""
@ -408,17 +388,11 @@ func (c *GinClient) MongoMiddleware() gin.HandlerFunc {
var traceId = gotrace_id.GetGinTraceId(ginCtx)
if dataJson {
if c.logDebug {
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.MongoMiddleware.mongoRecord.json.request_body]%s", jsonBody)
}
if c.logDebug {
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.MongoMiddleware]准备使用{mongoRecordJson}保存数据:%s", data)
}
c.mongoRecordJson(ginCtx, traceId, requestTime, string(data), responseCode, responseBody, startTime, endTime, clientIp, requestClientIpCountry, requestClientIpRegion, requestClientIpProvince, requestClientIpCity, requestClientIpIsp)
} else {
if c.logDebug {
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.MongoMiddleware.mongoRecord.xml.request_body]%s", xmlBody)
}
if c.logDebug {
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.MongoMiddleware]准备使用{mongoRecordXml}保存数据:%s", data)
}

@ -5,13 +5,12 @@ go 1.19
require (
github.com/gin-gonic/gin v1.8.1
github.com/natefinch/lumberjack v2.0.0+incompatible
go.dtapp.net/dorm v1.0.30
go.dtapp.net/dorm v1.0.31
go.dtapp.net/goip v1.0.28
go.dtapp.net/gorequest v1.0.28
go.dtapp.net/gotime v1.0.5
go.dtapp.net/gotrace_id v1.0.6
go.dtapp.net/gourl v1.0.0
go.dtapp.net/goxml v1.0.1
go.mongodb.org/mongo-driver v1.10.1
go.uber.org/zap v1.23.0
gorm.io/datatypes v1.0.7

@ -510,8 +510,8 @@ github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
go.dtapp.net/dorm v1.0.30 h1:B2gwSe1ov4S+LPUv1ijFm4XE2KEeNn85eCP4WLilsCU=
go.dtapp.net/dorm v1.0.30/go.mod h1:7ysGN47mW3u0EDAzXI3oUYZZHA3uasf2spugHeANPW8=
go.dtapp.net/dorm v1.0.31 h1:XEvg4gobAlWPfM9lCaklBqfQnPyqd6o9sFi1YIaDUSo=
go.dtapp.net/dorm v1.0.31/go.mod h1:ocdIcMoJCLGngRNPSAa/1Hq+Mu1JDTxT0hH2QBlL2ik=
go.dtapp.net/goip v1.0.28 h1:wZt+wbzNhOLRUJnepG4c8HhUr4V9jNXOF6wJ1h7jUvU=
go.dtapp.net/goip v1.0.28/go.mod h1:ZqPPUvpOSzdtB/dEZFiaD0CBRZmvIzjDmm3XkpMC9Bo=
go.dtapp.net/gorandom v1.0.1 h1:IWfMClh1ECPvyUjlqD7MwLq4mZdUusD1qAwAdsvEJBs=
@ -526,8 +526,6 @@ go.dtapp.net/gotrace_id v1.0.6 h1:q6s8jy50vt1820b69JKQaFqbhGS5yJGMVtocwOGOPO0=
go.dtapp.net/gotrace_id v1.0.6/go.mod h1:o5kSzNK4s3GrrKpkRKXtAhArtBG1e5N5O5KGPlBlWG4=
go.dtapp.net/gourl v1.0.0 h1:Zbe0GiMFyyRy2+bjbVsYulakH5d58w3CDZkUPonlMoQ=
go.dtapp.net/gourl v1.0.0/go.mod h1:x9A/pJ3iKDTb6Gu2RtJy2iHg56IowXIcIGQdogqpGjs=
go.dtapp.net/goxml v1.0.1 h1:WODsjNpmHTtoeLsXgOjC81qRbu4aXZ3LKBHApNGaPjY=
go.dtapp.net/goxml v1.0.1/go.mod h1:duD2uvBofiu/Rer1XQH2FyUhIkj6Zjapp4NDwRvoiQE=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
go.mongodb.org/mongo-driver v1.10.1 h1:NujsPveKwHaWuKUer/ceo9DzEe7HIj1SlJ6uvXZG0S4=

Loading…
Cancel
Save