mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-24 03:46:37 +02:00
eca0f35cb5
* add vars to http context * add query to http context * remove http deps * clean request decoder
28 lines
581 B
Go
28 lines
581 B
Go
package binding
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// BindQuery bind vars parameters to target.
|
|
func BindQuery(vars url.Values, target interface{}) error {
|
|
if msg, ok := target.(proto.Message); ok {
|
|
return mapProto(msg, vars)
|
|
}
|
|
return mapForm(target, vars)
|
|
}
|
|
|
|
// BindForm bind form parameters to target.
|
|
func BindForm(req *http.Request, target interface{}) error {
|
|
if err := req.ParseForm(); err != nil {
|
|
return err
|
|
}
|
|
if msg, ok := target.(proto.Message); ok {
|
|
return mapProto(msg, req.Form)
|
|
}
|
|
return mapForm(target, req.Form)
|
|
}
|