feat: delete useless

This commit is contained in:
engigu
2024-01-01 13:09:44 +08:00
parent 965ea46643
commit d8f8927c7c
14 changed files with 44 additions and 193 deletions
-22
View File
@@ -2,35 +2,13 @@ package app
import (
"fmt"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"github.com/go-playground/validator/v10"
"message-nest/pkg/e"
"message-nest/pkg/util"
"net/http"
"strings"
)
// BindAndValid binds and validates data
func BindAndValid(c *gin.Context, form interface{}) (int, int) {
err := c.Bind(form)
if err != nil {
return http.StatusBadRequest, e.INVALID_PARAMS
}
valid := validation.Validation{}
check, err := valid.Valid(form)
if err != nil {
return http.StatusInternalServerError, e.ERROR
}
if !check {
MarkErrors(valid.Errors)
return http.StatusBadRequest, e.INVALID_PARAMS
}
return http.StatusOK, e.SUCCESS
}
func CommonPlaygroundValid(obj interface{}) (int, string) {
if err := util.CustomerValidate.Struct(obj); err != nil {
errs := err.(validator.ValidationErrors)
-11
View File
@@ -2,20 +2,9 @@ package app
import (
"fmt"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"message-nest/pkg/logging"
)
// MarkErrors logs error logs
func MarkErrors(errors []*validation.Error) {
for _, err := range errors {
logging.Logger.Error(err.Key, err.Message)
}
return
}
// 从请求中获取当前用户
func GetCurrentUserName(c *gin.Context) string {
userName, ok := c.Get("currentUserName")
-12
View File
@@ -3,8 +3,6 @@ package app
import (
"github.com/gin-gonic/gin"
"net/http"
"message-nest/pkg/e"
)
type Gin struct {
@@ -17,16 +15,6 @@ type Response struct {
Data interface{} `json:"data"`
}
// Response setting gin.JSON
func (g *Gin) Response(httpCode, errCode int, data interface{}) {
g.C.JSON(httpCode, Response{
Code: errCode,
Msg: e.GetMsg(errCode),
Data: data,
})
return
}
func (g *Gin) CResponse(errCode int, Msg string, data interface{}) {
g.C.JSON(http.StatusOK, Response{
Code: errCode,