Pārlūkot izejas kodu

添加BindingForm函数

yjp 1 gadu atpakaļ
vecāks
revīzija
c7fbef9495
1 mainītis faili ar 11 papildinājumiem un 0 dzēšanām
  1. 11 0
      http_binding/request/request.go

+ 11 - 0
http_binding/request/request.go

@@ -39,3 +39,14 @@ func BindingMultipartForm[O any](c *binding_context.Context, request any, sendFu
 
 	return true
 }
+
+func BindingForm[T any](c *binding_context.Context, request interface{}, sendFunc response.SendFunc[T]) bool {
+	err := c.ShouldBindWith(request, binding.Form)
+	if err != nil {
+		var zero T
+		sendFunc(c, http.StatusBadRequest, zero, err)
+		return false
+	}
+
+	return true
+}