新增响应体与请求结构绑定

This commit is contained in:
shiran
2025-03-10 12:06:59 +08:00
parent b0650643bc
commit 64bda39e10
3 changed files with 38 additions and 1 deletions
+18
View File
@@ -0,0 +1,18 @@
package request
import (
"apiServer_service/utils/loger"
"fmt"
"github.com/cloudwego/hertz/pkg/app"
)
// BindRequestStruct 结构体参数绑定
func BindRequestStruct(c *app.RequestContext, request interface{}) error {
err := c.BindAndValidate(request)
if err != nil {
loger.Debug("BindRequestStruct", fmt.Sprintf("参数错误: %v", err))
BadRequest(c, "参数错误")
return err
}
return nil
}