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

27 lines
497 B
Go
Raw Normal View History

2021-04-20 07:55:55 +02:00
package httpin
2021-05-07 13:02:34 +02:00
2021-07-16 13:08:57 +02:00
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)
2021-05-07 13:02:34 +02:00
}