123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package request
- import (
- "git.sxidc.com/go-tools/api_binding/http_binding/binding_context"
- "git.sxidc.com/go-tools/api_binding/http_binding/response"
- "github.com/gin-gonic/gin/binding"
- "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
- }
- 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
- }
- func BindingXML[T any](c *binding_context.Context, request interface{}, sendFunc response.SendFunc[T]) bool {
- err := c.ShouldBindXML(request)
- if err != nil {
- var zero T
- sendFunc(c, http.StatusBadRequest, zero, err)
- return false
- }
- return true
- }
|