1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package request
- import (
- "github.com/gin-gonic/gin/binding"
- "lcp/api/binding/http_binding/binding_context"
- "lcp/api/binding/http_binding/response"
- "net/http"
- )
- func BindingJson[O any](c *binding_context.Context, request any, sendFunc response.SendFunc[O]) bool {
- err := c.ShouldBindJSON(request)
- if err != nil {
- var zero O
- sendFunc(c, http.StatusBadRequest, zero, err)
- return false
- }
- return true
- }
- func BindingQuery[O any](c *binding_context.Context, query any, sendFunc response.SendFunc[O]) bool {
- err := c.ShouldBindQuery(query)
- if err != nil {
- var zero O
- sendFunc(c, http.StatusBadRequest, zero, err)
- return false
- }
- return true
- }
- func BindingMultipartForm[O any](c *binding_context.Context, request any, sendFunc response.SendFunc[O]) bool {
- err := c.ShouldBindWith(request, binding.FormMultipart)
- if err != nil {
- var zero O
- sendFunc(c, http.StatusBadRequest, zero, err)
- return false
- }
- return true
- }
|