auto commit

master
李伟乐 11 months ago
parent 1abf072bc3
commit e001721edf
  1. 5
      transport/http/binding/bind.go

@ -3,13 +3,14 @@ package binding
import ( import (
"git.diulo.com/mogfee/kit/encoding" "git.diulo.com/mogfee/kit/encoding"
"git.diulo.com/mogfee/kit/encoding/form" "git.diulo.com/mogfee/kit/encoding/form"
"git.diulo.com/mogfee/kit/errors"
"net/http" "net/http"
"net/url" "net/url"
) )
func BindQuery(vars url.Values, target any) error { func BindQuery(vars url.Values, target any) error {
if err := encoding.GetCodec(form.Name).Unmarshal([]byte(vars.Encode()), target); err != nil { if err := encoding.GetCodec(form.Name).Unmarshal([]byte(vars.Encode()), target); err != nil {
return errorx.BadRequest("CODEC", err.Error()) return errors.BadRequest("CODEC", err.Error())
} }
return nil return nil
} }
@ -18,7 +19,7 @@ func BindForm(req *http.Request, target any) error {
return err return err
} }
if err := encoding.GetCodec(form.Name).Unmarshal([]byte(req.Form.Encode()), target); err != nil { if err := encoding.GetCodec(form.Name).Unmarshal([]byte(req.Form.Encode()), target); err != nil {
return errorx.BadRequest("CODEC", err.Error()) return errors.BadRequest("CODEC", err.Error())
} }
return nil return nil
} }

Loading…
Cancel
Save