|
|
|
@ -12,7 +12,6 @@ import (
|
|
|
|
|
"go.dtapp.net/gotime"
|
|
|
|
|
"go.dtapp.net/gotrace_id"
|
|
|
|
|
"go.dtapp.net/gourl"
|
|
|
|
|
"gorm.io/datatypes"
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"net"
|
|
|
|
@ -95,21 +94,19 @@ type ginPostgresqlLog struct {
|
|
|
|
|
RequestProto string `gorm:"comment:【请求】请求协议" json:"request_proto,omitempty"` //【请求】请求协议
|
|
|
|
|
RequestUa string `gorm:"comment:【请求】请求UA" json:"request_ua,omitempty"` //【请求】请求UA
|
|
|
|
|
RequestReferer string `gorm:"comment:【请求】请求referer" json:"request_referer,omitempty"` //【请求】请求referer
|
|
|
|
|
RequestBody datatypes.JSON `gorm:"type:jsonb;comment:【请求】请求主体" json:"request_body,omitempty"` //【请求】请求主体
|
|
|
|
|
RequestContent string `gorm:"comment:【请求】请求内容" json:"request_content,omitempty"` //【请求】请求内容
|
|
|
|
|
RequestUrlQuery datatypes.JSON `gorm:"type:jsonb;comment:【请求】请求URL参数" json:"request_url_query,omitempty"` //【请求】请求URL参数
|
|
|
|
|
RequestBody string `gorm:"comment:【请求】请求主体" json:"request_body,omitempty"` //【请求】请求主体
|
|
|
|
|
RequestUrlQuery string `gorm:"comment:【请求】请求URL参数" json:"request_url_query,omitempty"` //【请求】请求URL参数
|
|
|
|
|
RequestIp string `gorm:"index;comment:【请求】请求客户端Ip" json:"request_ip,omitempty"` //【请求】请求客户端Ip
|
|
|
|
|
RequestIpCountry string `gorm:"index;comment:【请求】请求客户端城市" json:"request_ip_country,omitempty"` //【请求】请求客户端城市
|
|
|
|
|
RequestIpRegion string `gorm:"index;comment:【请求】请求客户端区域" json:"request_ip_region,omitempty"` //【请求】请求客户端区域
|
|
|
|
|
RequestIpProvince string `gorm:"index;comment:【请求】请求客户端省份" json:"request_ip_province,omitempty"` //【请求】请求客户端省份
|
|
|
|
|
RequestIpCity string `gorm:"index;comment:【请求】请求客户端城市" json:"request_ip_city,omitempty"` //【请求】请求客户端城市
|
|
|
|
|
RequestIpIsp string `gorm:"index;comment:【请求】请求客户端运营商" json:"request_ip_isp,omitempty"` //【请求】请求客户端运营商
|
|
|
|
|
RequestHeader datatypes.JSON `gorm:"type:jsonb;comment:【请求】请求头" json:"request_header,omitempty"` //【请求】请求头
|
|
|
|
|
RequestHeader string `gorm:"comment:【请求】请求头" json:"request_header,omitempty"` //【请求】请求头
|
|
|
|
|
ResponseTime time.Time `gorm:"index;comment:【返回】时间" json:"response_time,omitempty"` //【返回】时间
|
|
|
|
|
ResponseCode int `gorm:"index;comment:【返回】状态码" json:"response_code,omitempty"` //【返回】状态码
|
|
|
|
|
ResponseMsg string `gorm:"comment:【返回】描述" json:"response_msg,omitempty"` //【返回】描述
|
|
|
|
|
ResponseData datatypes.JSON `gorm:"type:jsonb;comment:【返回】数据" json:"response_data,omitempty"` //【返回】数据
|
|
|
|
|
ResponseContent string `gorm:"comment:【返回】内容" json:"response_content,omitempty"` //【返回】内容
|
|
|
|
|
ResponseData string `gorm:"comment:【返回】数据" json:"response_data,omitempty"` //【返回】数据
|
|
|
|
|
CostTime int64 `gorm:"comment:【系统】花费时间" json:"cost_time,omitempty"` //【系统】花费时间
|
|
|
|
|
SystemHostName string `gorm:"index;comment:【系统】主机名" json:"system_host_name,omitempty"` //【系统】主机名
|
|
|
|
|
SystemInsideIp string `gorm:"index;comment:【系统】内网ip" json:"system_inside_ip,omitempty"` //【系统】内网ip
|
|
|
|
@ -149,18 +146,17 @@ func (c *GinClient) gormRecordJson(ginCtx *gin.Context, traceId string, requestT
|
|
|
|
|
RequestProto: ginCtx.Request.Proto, //【请求】请求协议
|
|
|
|
|
RequestUa: ginCtx.Request.UserAgent(), //【请求】请求UA
|
|
|
|
|
RequestReferer: ginCtx.Request.Referer(), //【请求】请求referer
|
|
|
|
|
RequestUrlQuery: datatypes.JSON(dorm.JsonEncodeNoError(ginCtx.Request.URL.Query())), //【请求】请求URL参数
|
|
|
|
|
RequestUrlQuery: dorm.JsonEncodeNoError(ginCtx.Request.URL.Query()), //【请求】请求URL参数
|
|
|
|
|
RequestIp: clientIp, //【请求】请求客户端Ip
|
|
|
|
|
RequestIpCountry: requestClientIpCountry, //【请求】请求客户端城市
|
|
|
|
|
RequestIpRegion: requestClientIpRegion, //【请求】请求客户端区域
|
|
|
|
|
RequestIpProvince: requestClientIpProvince, //【请求】请求客户端省份
|
|
|
|
|
RequestIpCity: requestClientIpCity, //【请求】请求客户端城市
|
|
|
|
|
RequestIpIsp: requestClientIpIsp, //【请求】请求客户端运营商
|
|
|
|
|
RequestHeader: datatypes.JSON(dorm.JsonEncodeNoError(ginCtx.Request.Header)), //【请求】请求头
|
|
|
|
|
RequestHeader: dorm.JsonEncodeNoError(ginCtx.Request.Header), //【请求】请求头
|
|
|
|
|
ResponseTime: gotime.Current().Time, //【返回】时间
|
|
|
|
|
ResponseCode: responseCode, //【返回】状态码
|
|
|
|
|
ResponseData: datatypes.JSON(responseBody), //【返回】数据
|
|
|
|
|
ResponseContent: responseBody, //【返回】内容
|
|
|
|
|
ResponseData: responseBody, //【返回】数据
|
|
|
|
|
CostTime: endTime - startTime, //【系统】花费时间
|
|
|
|
|
}
|
|
|
|
|
if ginCtx.Request.TLS == nil {
|
|
|
|
@ -170,8 +166,7 @@ func (c *GinClient) gormRecordJson(ginCtx *gin.Context, traceId string, requestT
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(requestBody) > 0 {
|
|
|
|
|
data.RequestBody = requestBody //【请求】请求主体
|
|
|
|
|
data.RequestContent = dorm.JsonEncodeNoError(requestBody) //【请求】请求内容
|
|
|
|
|
data.RequestBody = dorm.JsonEncodeNoError(requestBody) //【请求】请求主体
|
|
|
|
|
} else {
|
|
|
|
|
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.gormRecordJson.len]:%s,%s", data.RequestUri, requestBody)
|
|
|
|
|
}
|
|
|
|
@ -184,9 +179,7 @@ func (c *GinClient) gormRecordJson(ginCtx *gin.Context, traceId string, requestT
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordJson]:%s", err)
|
|
|
|
|
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordJson.string]:%s", requestBody)
|
|
|
|
|
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordJson.value]:%+v", requestBody)
|
|
|
|
|
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordJson.JsonEncodeNoError.string]:%s", dorm.JsonEncodeNoError(requestBody))
|
|
|
|
|
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordJson.JsonEncodeNoError.value]:%+v", dorm.JsonEncodeNoError(requestBody))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -205,18 +198,17 @@ func (c *GinClient) gormRecordXml(ginCtx *gin.Context, traceId string, requestTi
|
|
|
|
|
RequestProto: ginCtx.Request.Proto, //【请求】请求协议
|
|
|
|
|
RequestUa: ginCtx.Request.UserAgent(), //【请求】请求UA
|
|
|
|
|
RequestReferer: ginCtx.Request.Referer(), //【请求】请求referer
|
|
|
|
|
RequestUrlQuery: datatypes.JSON(dorm.JsonEncodeNoError(ginCtx.Request.URL.Query())), //【请求】请求URL参数
|
|
|
|
|
RequestUrlQuery: dorm.JsonEncodeNoError(ginCtx.Request.URL.Query()), //【请求】请求URL参数
|
|
|
|
|
RequestIp: clientIp, //【请求】请求客户端Ip
|
|
|
|
|
RequestIpCountry: requestClientIpCountry, //【请求】请求客户端城市
|
|
|
|
|
RequestIpRegion: requestClientIpRegion, //【请求】请求客户端区域
|
|
|
|
|
RequestIpProvince: requestClientIpProvince, //【请求】请求客户端省份
|
|
|
|
|
RequestIpCity: requestClientIpCity, //【请求】请求客户端城市
|
|
|
|
|
RequestIpIsp: requestClientIpIsp, //【请求】请求客户端运营商
|
|
|
|
|
RequestHeader: datatypes.JSON(dorm.JsonEncodeNoError(ginCtx.Request.Header)), //【请求】请求头
|
|
|
|
|
RequestHeader: dorm.JsonEncodeNoError(ginCtx.Request.Header), //【请求】请求头
|
|
|
|
|
ResponseTime: gotime.Current().Time, //【返回】时间
|
|
|
|
|
ResponseCode: responseCode, //【返回】状态码
|
|
|
|
|
ResponseData: datatypes.JSON(responseBody), //【返回】数据
|
|
|
|
|
ResponseContent: responseBody, //【返回】内容
|
|
|
|
|
ResponseData: responseBody, //【返回】数据
|
|
|
|
|
CostTime: endTime - startTime, //【系统】花费时间
|
|
|
|
|
}
|
|
|
|
|
if ginCtx.Request.TLS == nil {
|
|
|
|
@ -226,7 +218,7 @@ func (c *GinClient) gormRecordXml(ginCtx *gin.Context, traceId string, requestTi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(requestBody) > 0 {
|
|
|
|
|
data.RequestContent = dorm.XmlEncodeNoError(dorm.XmlDecodeNoError(requestBody)) //【请求】请求内容
|
|
|
|
|
data.RequestBody = dorm.XmlEncodeNoError(dorm.XmlDecodeNoError(requestBody)) //【请求】请求内容
|
|
|
|
|
} else {
|
|
|
|
|
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[golog.gin.gormRecordXml.len]:%s,%s", data.RequestUri, requestBody)
|
|
|
|
|
}
|
|
|
|
@ -239,11 +231,8 @@ func (c *GinClient) gormRecordXml(ginCtx *gin.Context, traceId string, requestTi
|
|
|
|
|
if err != nil {
|
|
|
|
|
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.XmlDecodeNoError.string]:%s", dorm.XmlDecodeNoError(requestBody))
|
|
|
|
|
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordXml.XmlDecodeNoError.value]:%+v", dorm.XmlDecodeNoError(requestBody))
|
|
|
|
|
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordXml.XmlEncodeNoError.string]:%s", dorm.XmlEncodeNoError(dorm.XmlDecodeNoError(requestBody)))
|
|
|
|
|
c.zapLog.WithTraceIdStr(traceId).Sugar().Errorf("[golog.gin.gormRecordXml.XmlEncodeNoError.value]:%+v", dorm.XmlEncodeNoError(dorm.XmlDecodeNoError(requestBody)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|