Skip to content

Commit 87486d6

Browse files
committed
add: 加密场景可以直接设置
1 parent 78a5f52 commit 87486d6

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.18
44

55
require (
66
github.com/gin-gonic/gin v1.8.1
7-
github.com/go-home-admin/home v0.5.0
7+
github.com/go-home-admin/home v0.5.14
88
github.com/satori/go.uuid v1.2.0
99
github.com/sirupsen/logrus v1.9.0
1010
gorm.io/gorm v1.23.8

telescope_provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ func getGoId() uint64 {
153153
type TelescopeResponseWriter struct {
154154
gin.ResponseWriter
155155
Body *bytes.Buffer
156+
// 如果有解密的系统, 直接设置这个值才回正常记录
157+
DecodeBody []byte
156158
}
157159

158160
func (w TelescopeResponseWriter) Write(b []byte) (int, error) {

type_request.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,32 @@ func (b Request) Handler(entry *logrus.Entry) (*entries, []tag) {
4444
ginCtx := ctx.(*gin.Context)
4545
res = ginCtx.Writer
4646
telescopeResp := res.(*TelescopeResponseWriter)
47+
responseBody := telescopeResp.Body.Bytes()
48+
if len(telescopeResp.DecodeBody) != 0 {
49+
responseBody = telescopeResp.DecodeBody
50+
}
4751

4852
responseJSON := map[string]interface{}{}
49-
err := json.Unmarshal(telescopeResp.Body.Bytes(), &responseJSON)
53+
err := json.Unmarshal(responseBody, &responseJSON)
5054
if err != nil || len(responseJSON) == 0 {
5155
b.Response = telescopeResp.Body.String()
5256
} else {
5357
b.Response = responseJSON
5458
}
5559

56-
// 原始请求数据
57-
if ginCtx.Request.PostForm == nil {
58-
raw, ok := ginCtx.Get("raw")
59-
if ok {
60-
switch raw.(type) {
61-
case string:
62-
data := raw.(string)
63-
_ = json.Unmarshal([]byte(data), &b.Payload)
64-
case []byte:
65-
data := raw.([]byte)
66-
_ = json.Unmarshal(data, &b.Payload)
67-
}
60+
// 原始请求数据, 如果加密场景可以直接设置
61+
raw, ok := ginCtx.Get("raw")
62+
if ok {
63+
switch raw.(type) {
64+
case string:
65+
data := raw.(string)
66+
_ = json.Unmarshal([]byte(data), &b.Payload)
67+
case []byte:
68+
data := raw.([]byte)
69+
_ = json.Unmarshal(data, &b.Payload)
6870
}
69-
} else {
71+
}
72+
if ginCtx.Request.PostForm != nil {
7073
for k, v := range ginCtx.Request.PostForm {
7174
b.Payload[k] = v[0]
7275
}

0 commit comments

Comments
 (0)