|
|
|
@ -6,6 +6,7 @@ import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"go.dtapp.net/gojson"
|
|
|
|
|
"go.dtapp.net/gorequest"
|
|
|
|
|
"go.dtapp.net/gotime"
|
|
|
|
|
"go.dtapp.net/gotrace_id"
|
|
|
|
|
"go.dtapp.net/gourl"
|
|
|
|
@ -97,6 +98,8 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
|
|
var ctx = gotrace_id.SetGinTraceIdContext(context.Background(), ginCtx)
|
|
|
|
|
|
|
|
|
|
// 解析请求内容
|
|
|
|
|
var xmlBody map[string]string
|
|
|
|
|
var jsonBody map[string]interface{}
|
|
|
|
@ -105,19 +108,21 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
|
|
|
|
|
xmlBody = goxml.XmlDecode(string(data))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clientIp := gorequest.ClientIp(ginCtx.Request)
|
|
|
|
|
|
|
|
|
|
requestClientIpCountry, requestClientIpRegion, requestClientIpProvince, requestClientIpCity, requestClientIpIsp := "", "", "", "", ""
|
|
|
|
|
if c.ipService != nil {
|
|
|
|
|
if net.ParseIP(ginCtx.ClientIP()).To4() != nil {
|
|
|
|
|
if net.ParseIP(clientIp).To4() != nil {
|
|
|
|
|
// 判断是不是IPV4
|
|
|
|
|
_, info := c.ipService.Ipv4(ginCtx.ClientIP())
|
|
|
|
|
_, info := c.ipService.Ipv4(clientIp)
|
|
|
|
|
requestClientIpCountry = info.Country
|
|
|
|
|
requestClientIpRegion = info.Region
|
|
|
|
|
requestClientIpProvince = info.Province
|
|
|
|
|
requestClientIpCity = info.City
|
|
|
|
|
requestClientIpIsp = info.ISP
|
|
|
|
|
} else if net.ParseIP(ginCtx.ClientIP()).To16() != nil {
|
|
|
|
|
} else if net.ParseIP(clientIp).To16() != nil {
|
|
|
|
|
// 判断是不是IPV6
|
|
|
|
|
info := c.ipService.Ipv6(ginCtx.ClientIP())
|
|
|
|
|
info := c.ipService.Ipv6(clientIp)
|
|
|
|
|
requestClientIpCountry = info.Country
|
|
|
|
|
requestClientIpProvince = info.Province
|
|
|
|
|
requestClientIpCity = info.City
|
|
|
|
@ -145,7 +150,7 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
|
|
|
|
|
RequestReferer: ginCtx.Request.Referer(), //【请求】请求referer
|
|
|
|
|
RequestBody: datatypes.JSON(gojson.JsonEncodeNoError(jsonBody)), //【请求】请求主体
|
|
|
|
|
RequestUrlQuery: datatypes.JSON(gojson.JsonEncodeNoError(ginCtx.Request.URL.Query())), //【请求】请求URL参数
|
|
|
|
|
RequestIp: ginCtx.ClientIP(), //【请求】请求客户端Ip
|
|
|
|
|
RequestIp: clientIp, //【请求】请求客户端Ip
|
|
|
|
|
RequestIpCountry: requestClientIpCountry, //【请求】请求客户端城市
|
|
|
|
|
RequestIpRegion: requestClientIpRegion, //【请求】请求客户端区域
|
|
|
|
|
RequestIpProvince: requestClientIpProvince, //【请求】请求客户端省份
|
|
|
|
@ -159,7 +164,7 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
if c.config.logDebug == true {
|
|
|
|
|
c.logClient.Errorf(gotrace_id.SetGinTraceIdContext(context.Background(), ginCtx), err.Error())
|
|
|
|
|
c.logClient.Errorf(ctx, err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -175,7 +180,7 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
|
|
|
|
|
RequestReferer: ginCtx.Request.Referer(), //【请求】请求referer
|
|
|
|
|
RequestBody: datatypes.JSON(gojson.JsonEncodeNoError(xmlBody)), //【请求】请求主体
|
|
|
|
|
RequestUrlQuery: datatypes.JSON(gojson.JsonEncodeNoError(ginCtx.Request.URL.Query())), //【请求】请求URL参数
|
|
|
|
|
RequestIp: ginCtx.ClientIP(), //【请求】请求客户端Ip
|
|
|
|
|
RequestIp: clientIp, //【请求】请求客户端Ip
|
|
|
|
|
RequestIpCountry: requestClientIpCountry, //【请求】请求客户端城市
|
|
|
|
|
RequestIpRegion: requestClientIpRegion, //【请求】请求客户端区域
|
|
|
|
|
RequestIpProvince: requestClientIpProvince, //【请求】请求客户端省份
|
|
|
|
@ -189,7 +194,7 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
if c.config.logDebug == true {
|
|
|
|
|
c.logClient.Errorf(gotrace_id.SetGinTraceIdContext(context.Background(), ginCtx), "[log.gormRecord]%s", err.Error())
|
|
|
|
|
c.logClient.Errorf(ctx, "[log.gormRecord]%s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|