This commit is contained in:
oneao committed 2026-02-26 17:31:08 +08:00
1 parent 4ce951dd56
commit 8a3dea8545
44 files changed
+1599 -30

No files matched your search

@@ -0,0 +1,22 @@
package requestx
import (
"allapp/utils/responsex"
"errors"
"github.com/go-playground/validator/v10"
"github.com/gofiber/fiber/v3"
)
// BindAndValidate 封装请求体解析和校验
func BindAndValidate(c fiber.Ctx, v any) error {
if err := c.Bind().Body(v); err != nil {
// Handle validation errors
var validationErrors validator.ValidationErrors
if errors.As(err, &validationErrors) {
return responsex.Error(c, "参数校验失败")
}
return err
}
return nil
}