李伟乐 2 years ago
parent bed0adc9d2
commit 57c959790d
  1. 19
      response/response.go

@ -21,12 +21,27 @@ func New(ctx *gin.Context) *result {
func (s *result) BindQuery(v any) error {
decoder := form.NewDecoder()
decoder.SetTagName("json")
return decoder.Decode(v, s.ctx.Request.URL.Query())
err := decoder.Decode(v, s.ctx.Request.URL.Query())
if err != nil {
return err
}
return s.Validate(v)
}
func (s *result) Validate(v any) error {
if vv, ok := v.(interface {
Validate() error
}); ok {
return vv.Validate()
}
return nil
}
func (s *result) BindJSON(v any) error {
body := s.ctx.Request.Body
decoder := json.NewDecoder(body)
return decoder.Decode(v)
if err := decoder.Decode(v); err != nil {
return err
}
return s.Validate(v)
}
func (s *result) Error(err error) {
if err == nil {

Loading…
Cancel
Save