🆕接入验证码组件

This commit is contained in:
coward
2024-03-06 17:13:29 +08:00
parent 7fd186d298
commit c820672f89
9 changed files with 151 additions and 2 deletions

44
utils/gin_response.go Normal file
View File

@@ -0,0 +1,44 @@
package utils
import (
"fmt"
"github.com/gin-gonic/gin"
"net/http"
)
type ginResponse struct {
c *gin.Context
}
func GinResponse(c *gin.Context) ginResponse {
return ginResponse{c: c}
}
func (r ginResponse) OK() {
r.c.JSON(http.StatusOK, gin.H{
"code": http.StatusOK,
"message": "success",
})
}
func (r ginResponse) Failed() {
r.c.JSON(http.StatusBadRequest, gin.H{
"code": http.StatusBadRequest,
"message": "bad request",
})
}
func (r ginResponse) FailedWithErr(msg string, err error) {
r.c.JSON(http.StatusBadRequest, gin.H{
"code": http.StatusBadRequest,
"message": fmt.Errorf("%s: %s", msg, err.Error()),
})
}
func (r ginResponse) OKWithData(data any) {
r.c.JSON(http.StatusOK, gin.H{
"code": http.StatusOK,
"message": "success",
"data": data,
})
}