修复日志参数问题不插入问题

This commit is contained in:
junleea 2024-06-12 18:03:19 +08:00
parent bfde7176eb
commit 3ee0bc61bd
1 changed files with 9 additions and 5 deletions

14
main.go
View File

@ -1,9 +1,11 @@
package main
import (
"context"
"fmt"
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt"
"io"
"strings"
"videoplayer/dao"
"videoplayer/handler"
@ -36,12 +38,14 @@ func writeLogger(c *gin.Context) {
params = c.Request.URL.RawQuery
}
if method == "POST" {
var data interface{}
err := c.ShouldBind(&data)
if err != nil {
fmt.Println("bind json failed")
params = c.Request.PostForm.Encode()
if params == "" {
// 克隆请求
req := c.Request.Clone(context.Background())
// 读取原始请求体内容
bodyBytes, _ := io.ReadAll(req.Body)
params = string(bodyBytes)
}
params = fmt.Sprintf("%v", data)
}
res := dao.InsertLogToDB(path, ip, method, params)
if res == 0 {