func (r *response) Read(data interface{}) error {
	switch {
	case r.HasContentType(rest.ContentTypeGOB):
		dec := gob.NewDecoder(bytes.NewBuffer(r.content))
		if err := dec.Decode(data); err != nil {
			return errors.Annotate(err, ErrDecodingResponse, errorMessages)
		}
		return nil
	case r.HasContentType(rest.ContentTypeJSON):
		if err := json.Unmarshal(r.content, &data); err != nil {
			return errors.Annotate(err, ErrDecodingResponse, errorMessages)
		}
		return nil
	case r.HasContentType(rest.ContentTypeXML):
		if err := xml.Unmarshal(r.content, &data); err != nil {
			return errors.Annotate(err, ErrDecodingResponse, errorMessages)
		}
		return nil
	case r.HasContentType(rest.ContentTypeURLEncoded):
		values, err := url.ParseQuery(string(r.content))
		if err != nil {
			return errors.Annotate(err, ErrDecodingResponse, errorMessages)
		}
		// Check for data type url.Values.
		duv, ok := data.(url.Values)
		if ok {
			for key, value := range values {
				duv[key] = value
			}
			return nil
		}
		// Check for data type KeyValues.
		kvv, ok := data.(KeyValues)
		if !ok {
			return errors.New(ErrDecodingResponse, errorMessages)
		}
		for key, value := range values {
			kvv[key] = strings.Join(value, " / ")
		}
		return nil
	}
	return errors.New(ErrInvalidContentType, errorMessages, r.contentType)
}
// Read implements the Response interface.
Read implements the Response interface.
// Read implements the Response interface .
func (r *response) Read(data interface{}) error {
	switch {
	case r.HasContentType(rest.ContentTypeGOB):
		dec := gob.NewDecoder(bytes.NewBuffer(r.content))
		if err := dec.Decode(data); err != nil {
			return errors.Annotate(err, ErrDecodingResponse, errorMessages)
		}
		return nil
	case r.HasContentType(rest.ContentTypeJSON):
		if err := json.Unmarshal(r.content, &data); err != nil {
			return errors.Annotate(err, ErrDecodingResponse, errorMessages)
		}
		return nil
	case r.HasContentType(rest.ContentTypeXML):
		if err := xml.Unmarshal(r.content, &data); err != nil {
			return errors.Annotate(err, ErrDecodingResponse, errorMessages)
		}
		return nil
	case r.HasContentType(rest.ContentTypeURLEncoded):
		values, err := url.ParseQuery(string(r.content))
		if err != nil {
			return errors.Annotate(err, ErrDecodingResponse, errorMessages)
		}
		duv, ok := data.(url.Values)
		if ok {
			for key, value := range values {
				duv[key] = value
			}
			return nil
		}
		kvv, ok := data.(KeyValues)
		if !ok {
			return errors.New(ErrDecodingResponse, errorMessages)
		}
		for key, value := range values {
			kvv[key] = strings.Join(value, " / ")
		}
		return nil
	}
	return errors.New(ErrInvalidContentType, errorMessages, r.contentType)
}
func ( r * response ) Read ( data interface { } ) error { switch { case r . HasContentType ( rest . ContentTypeGOB ) : dec := gob . NewDecoder ( bytes . NewBuffer ( r . content ) ) if err := dec . Decode ( data ) ; err != nil { return errors . Annotate ( err , ErrDecodingResponse , errorMessages ) } return nil case r . HasContentType ( rest . ContentTypeJSON ) : if err := json . Unmarshal ( r . content , & data ) ; err != nil { return errors . Annotate ( err , ErrDecodingResponse , errorMessages ) } return nil case r . HasContentType ( rest . ContentTypeXML ) : if err := xml . Unmarshal ( r . content , & data ) ; err != nil { return errors . Annotate ( err , ErrDecodingResponse , errorMessages ) } return nil case r . HasContentType ( rest . ContentTypeURLEncoded ) : values , err := url . ParseQuery ( string ( r . content ) ) if err != nil { return errors . Annotate ( err , ErrDecodingResponse , errorMessages ) } duv , ok := data . ( url . Values ) if ok { for key , value := range values { duv [ key ] = value } return nil } kvv , ok := data . ( KeyValues ) if ! ok { return errors . New ( ErrDecodingResponse , errorMessages ) } for key , value := range values { kvv [ key ] = strings . Join ( value , " " ) } return nil } return errors . New ( ErrInvalidContentType , errorMessages , r . contentType ) }
Read implements the Response interface.
Read implements the Response interface .
// Check for data type url.Values. // Check for data type KeyValues.