mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
fix: 解决操作日志解析失败的问题 (#585)
This commit is contained in:
parent
b9e1de8446
commit
3ac467fc53
@ -2,6 +2,7 @@ package middleware
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -129,8 +130,23 @@ func OperationLog() gin.HandlerFunc {
|
||||
|
||||
c.Next()
|
||||
|
||||
buf := bytes.NewReader(writer.body.Bytes())
|
||||
reader, err := gzip.NewReader(buf)
|
||||
if err != nil {
|
||||
record.Status = constant.StatusFailed
|
||||
record.Message = fmt.Sprintf("gzip new reader failed, err: %v", err)
|
||||
latency := time.Since(now)
|
||||
record.Latency = latency
|
||||
|
||||
if err := service.NewILogService().CreateOperationLog(record); err != nil {
|
||||
global.LOG.Errorf("create operation record failed, err: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
defer reader.Close()
|
||||
datas, _ := io.ReadAll(reader)
|
||||
var res response
|
||||
_ = json.Unmarshal(writer.body.Bytes(), &res)
|
||||
_ = json.Unmarshal(datas, &res)
|
||||
if res.Code == 200 {
|
||||
record.Status = constant.StatusSuccess
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user