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

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 package main
import ( import (
"context"
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt" "github.com/golang-jwt/jwt"
"io"
"strings" "strings"
"videoplayer/dao" "videoplayer/dao"
"videoplayer/handler" "videoplayer/handler"
@ -36,12 +38,14 @@ func writeLogger(c *gin.Context) {
params = c.Request.URL.RawQuery params = c.Request.URL.RawQuery
} }
if method == "POST" { if method == "POST" {
var data interface{} params = c.Request.PostForm.Encode()
err := c.ShouldBind(&data) if params == "" {
if err != nil { // 克隆请求
fmt.Println("bind json failed") 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) res := dao.InsertLogToDB(path, ip, method, params)
if res == 0 { if res == 0 {