mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-16 02:47:03 +02:00
23a7f15541
* add form for http codec
23 lines
576 B
Go
23 lines
576 B
Go
package binding
|
|
|
|
import (
|
|
"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 {
|
|
return encoding.GetCodec(form.Name).Unmarshal([]byte(vars.Encode()), target)
|
|
}
|
|
|
|
// BindForm bind form parameters to target.
|
|
func BindForm(req *http.Request, target interface{}) error {
|
|
if err := req.ParseForm(); err != nil {
|
|
return err
|
|
}
|
|
return encoding.GetCodec(form.Name).Unmarshal([]byte(req.Form.Encode()), target)
|
|
}
|