修复日志参数问题不插入问题
This commit is contained in:
parent
bfde7176eb
commit
3ee0bc61bd
14
main.go
14
main.go
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue