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
|
|
|
}
|