fix xreponse
This commit is contained in:
parent
2421f038e6
commit
53d01fb04d
|
@ -2,6 +2,7 @@ package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"service/library/logger"
|
"service/library/logger"
|
||||||
|
@ -86,18 +87,24 @@ func LoggerMiddleware(conf gin.LoggerConfig) gin.HandlerFunc {
|
||||||
|
|
||||||
param.Path = path
|
param.Path = path
|
||||||
|
|
||||||
var bodyStr string
|
var bodyBytes []byte
|
||||||
body, ok := c.Get(gin.BodyBytesKey)
|
body, ok := c.Get(gin.BodyBytesKey)
|
||||||
if ok {
|
if ok {
|
||||||
bodyStr = string(body.([]byte))
|
bodyBytes = body.([]byte)
|
||||||
}
|
}
|
||||||
if _, ok := NoLogRoutesMap[param.Path]; !ok {
|
if _, ok := NoLogRoutesMap[param.Path]; !ok {
|
||||||
logger.Info("%s params: %s", formatter(param), bodyStr)
|
logger.Info("%s params: %s", formatter(param), string(bodyBytes))
|
||||||
}
|
}
|
||||||
if strings.Contains(param.Path, "is_there_a_new_version_available") {
|
if strings.Contains(param.Path, "is_there_a_new_version_available") {
|
||||||
logger.Info("%s response: %s", formatter(param), blw.body.String())
|
logger.Info("%s response: %s", formatter(param), blw.body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bReq := BaseRequest{}
|
||||||
|
_ = json.Unmarshal(bodyBytes, &bReq)
|
||||||
|
if bReq.Mid == 161 {
|
||||||
|
logger.Info("%s xresponse: %s", formatter(param), blw.body.String())
|
||||||
|
}
|
||||||
|
|
||||||
//logger.WithCtx(c.Request.Context()).Info("%s params: %s", formatter(param), bodyStr)
|
//logger.WithCtx(c.Request.Context()).Info("%s params: %s", formatter(param), bodyStr)
|
||||||
//if accessConf.LogResponseEnabled {
|
//if accessConf.LogResponseEnabled {
|
||||||
// logger.WithCtx(c.Request.Context()).Info("%s response: %s", formatter(param), blw.body.String())
|
// logger.WithCtx(c.Request.Context()).Info("%s response: %s", formatter(param), blw.body.String())
|
||||||
|
@ -109,3 +116,20 @@ func LoggerMiddleware(conf gin.LoggerConfig) gin.HandlerFunc {
|
||||||
var NoLogRoutesMap = map[string]bool{
|
var NoLogRoutesMap = map[string]bool{
|
||||||
"/healthcheck": true,
|
"/healthcheck": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BaseRequest struct {
|
||||||
|
Mid int64 `json:"b_mid"` // 用户id
|
||||||
|
Did string `json:"b_did"` // 设备id
|
||||||
|
Version string `json:"b_ver"` // 版本
|
||||||
|
OsVersion string `json:"b_osver"` // 系统版本
|
||||||
|
DevType int32 `json:"b_dt"` // 设备类型
|
||||||
|
Channel string `json:"b_ch"` // 渠道
|
||||||
|
Model string `json:"b_model"` // 机型
|
||||||
|
NetType string `json:"b_nt"` // 网络类型
|
||||||
|
Timestamp int64 `json:"b_ts"` // 时间戳,毫秒
|
||||||
|
Token string `json:"b_token"` // 令牌
|
||||||
|
Location struct {
|
||||||
|
Lat float64 `json:"b_lat"`
|
||||||
|
Lon float64 `json:"b_lon"`
|
||||||
|
} `json:"b_loc"` // 经纬度
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue