response.go 382 B

123456789101112131415161718192021222324
  1. package xhttp
  2. import (
  3. "encoding/json"
  4. "encoding/xml"
  5. "net/http"
  6. )
  7. // Message HTTP response
  8. type Message struct {
  9. StatusCode int
  10. Body []byte
  11. Header http.Header
  12. }
  13. // JSON Body to JSON
  14. func (m Message) JSON(v interface{}) error {
  15. return json.Unmarshal(m.Body, v)
  16. }
  17. // XML Body to XML
  18. func (m Message) XML(v interface{}) error {
  19. return xml.Unmarshal(m.Body, v)
  20. }