package binding import ( "git.sxidc.com/go-framework/baize/api" "git.sxidc.com/service-supports/fserr" "github.com/gin-gonic/gin/binding" ) type DTO interface{} func ToConcreteDTO[T DTO](object DTO) (T, error) { concrete, ok := object.(T) if !ok { var zero T return zero, fserr.New("DTO转化失败") } return concrete, nil } func JsonBody(c *api.Context, dto DTO) error { return c.ShouldBindJSON(dto) } func QueryParams(c *api.Context, dto DTO) error { return c.ShouldBindQuery(dto) } func PathParams(c *api.Context, dto DTO) error { return c.ShouldBindUri(dto) } func MultipartForm(c *api.Context, dto DTO) error { return c.ShouldBindWith(dto, binding.FormMultipart) } func Form(c *api.Context, dto DTO) error { return c.ShouldBindWith(dto, binding.Form) } func XMLBody(c *api.Context, dto DTO) error { return c.ShouldBindXML(dto) }