You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
779 B
29 lines
779 B
package binding
|
|
|
|
import (
|
|
"github.com/go-kratos/kratos/v2/errors"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"github.com/go-kratos/kratos/v2/encoding"
|
|
"github.com/go-kratos/kratos/v2/encoding/form"
|
|
)
|
|
|
|
// BindQuery bind vars parameters to target.
|
|
func BindQuery(vars url.Values, target interface{}) error {
|
|
if err := encoding.GetCodec(form.Name).Unmarshal([]byte(vars.Encode()), target); err != nil {
|
|
return errors.BadRequest("CODEC", err.Error())
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// BindForm bind form parameters to target.
|
|
func BindForm(req *http.Request, target interface{}) error {
|
|
if err := req.ParseForm(); err != nil {
|
|
return err
|
|
}
|
|
if err := encoding.GetCodec(form.Name).Unmarshal([]byte(req.Form.Encode()), target); err != nil {
|
|
return errors.BadRequest("CODEC", err.Error())
|
|
}
|
|
return nil
|
|
}
|
|
|