修复日志参数问题,用户请求的bug

This commit is contained in:
junleea 2024-06-12 17:43:15 +08:00
parent 5befe12ae6
commit bfde7176eb
3 changed files with 13 additions and 3 deletions

View File

@ -47,7 +47,8 @@ func ScanUUID(c *gin.Context) {
id := uuid.New()
res := worker.SetHash(id.String(), map[string]interface{}{"status": "0", "address": ReqData.Address, "ip": c.ClientIP()})
if res {
c.JSON(200, gin.H{"code": 0, "message": "success", "data": id.String()})
data := worker.GetHashAll(id.String())
c.JSON(200, gin.H{"code": 0, "message": data, "data": id.String()})
} else {
c.JSON(200, gin.H{"code": 8, "message": "qr code invalid", "data": "1"})
}
@ -56,6 +57,10 @@ func ScanUUID(c *gin.Context) {
func SetQRStatus(c *gin.Context) {
var qrsetReq QRReq
if err := c.ShouldBind(&qrsetReq); err == nil || qrsetReq.UUID != "" {
if worker.IsContainKey(qrsetReq.UUID) == false {
c.JSON(200, gin.H{"code": 18, "message": "uuid not found", "data": "0"})
return
}
res := worker.SetHashWithField(qrsetReq.UUID, "status", "1")
if res {
data := worker.GetHashAll(qrsetReq.UUID)

View File

@ -36,7 +36,12 @@ func writeLogger(c *gin.Context) {
params = c.Request.URL.RawQuery
}
if method == "POST" {
params = c.Request.PostForm.Encode()
var data interface{}
err := c.ShouldBind(&data)
if err != nil {
fmt.Println("bind json failed")
}
params = fmt.Sprintf("%v", data)
}
res := dao.InsertLogToDB(path, ip, method, params)
if res == 0 {

View File

@ -35,7 +35,7 @@ func CloseRedis() {
}
}
func isContainKey(key string) bool {
func IsContainKey(key string) bool {
ctx := context.Background()
val, err := redisClient.Exists(ctx, key).Result() // 检查键是否存在, 如果存在则返回 1, 否则返回 0
if err != nil {