Browse Source

添加BindingForm函数

yjp 1 year ago
parent
commit
c7fbef9495
1 changed files with 11 additions and 0 deletions
  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
+}