1
0
mirror of https://github.com/ggicci/httpin.git synced 2024-11-24 08:32:45 +02:00
httpin/body.go
2021-07-16 19:08:57 +08:00

27 lines
497 B
Go

package httpin
import (
"encoding/json"
"encoding/xml"
"net/http"
"reflect"
)
type JSONBody struct{}
type XMLBody struct{}
var (
typeJSONBody = reflect.TypeOf(JSONBody{})
typeXMLBody = reflect.TypeOf(XMLBody{})
)
func decodeJSONBody(req *http.Request, rv reflect.Value) error {
obj := rv.Interface()
return json.NewDecoder(req.Body).Decode(&obj)
}
func decodeXMLBody(req *http.Request, rv reflect.Value) error {
obj := rv.Interface()
return xml.NewDecoder(req.Body).Decode(&obj)
}