refactor: adjust project structure

This commit is contained in:
2024-11-14 01:15:55 +08:00
parent c219d81b89
commit 70d7229dd8
20 changed files with 320 additions and 132 deletions

View File

@ -0,0 +1,52 @@
package sms
import (
"errors"
"fmt"
"github.com/gin-gonic/gin"
"github.com/redis/go-redis/v9"
"health-go/config"
"net/http"
)
func Validate(c *gin.Context) {
var user struct {
Tel string `json:"tel"`
Code string `json:"code"`
}
if err := c.ShouldBindJSON(&user); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"code": 400,
"msg": "无效的请求参数",
"data": nil,
})
return
}
storageCode, err := config.RDC.Get(config.CTX, user.Tel).Result()
fmt.Println("storageCode:", storageCode)
if errors.Is(err, redis.Nil) {
c.JSON(http.StatusOK, gin.H{
"code": 200,
"msg": "验证码已过期",
"data": nil,
})
return
}
if user.Code != storageCode {
c.JSON(http.StatusOK, gin.H{
"code": 200,
"msg": "验证码错误",
"data": nil,
})
} else {
fmt.Println("验证码正确删除redis中的验证码")
config.RDC.Del(config.CTX, user.Tel)
c.JSON(http.StatusOK, gin.H{"code": 200,
"msg": "验证码正确",
"data": nil,
})
}
}