2021-03-03 22:22:59 +08:00
|
|
|
package binding
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
2021-05-21 23:11:36 +08:00
|
|
|
|
2021-05-22 11:14:55 +08:00
|
|
|
// BindVars bind map parameters to target.
|
2021-06-12 18:30:17 +08:00
|
|
|
func BindVars(values map[string][]string, target interface{}) error {
|
2021-05-21 23:11:36 +08:00
|
|
|
if msg, ok := target.(proto.Message); ok {
|
|
|
|
return mapProto(msg, values)
|
|
|
|
}
|
|
|
|
return mapForm(target, values)
|
|
|
|
}
|