MCPcopy Create free account
hub / github.com/goadesign/goa / ResponseDecoder

Function ResponseDecoder

http/encoding.go:232–253  ·  view source on GitHub ↗

ResponseDecoder returns a HTTP response decoder. The decoder handles the following content types: - application/json using package encoding/json (default) - application/xml using package encoding/xml - application/gob using package encoding/gob - text/html and text/plain for strings

(resp *http.Response)

Source from the content-addressed store, hash-verified

230// - application/gob using package encoding/gob
231// - text/html and text/plain for strings
232func ResponseDecoder(resp *http.Response) Decoder {
233 ct := resp.Header.Get("Content-Type")
234 if ct == "" {
235 return json.NewDecoder(resp.Body)
236 }
237 if mediaType, _, err := mime.ParseMediaType(ct); err == nil {
238 ct = mediaType
239 }
240 switch {
241 case ct == "application/json" || strings.HasSuffix(ct, "+json"):
242 return json.NewDecoder(resp.Body)
243 case ct == "application/xml" || strings.HasSuffix(ct, "+xml"):
244 return xml.NewDecoder(resp.Body)
245 case ct == "application/gob" || strings.HasSuffix(ct, "+gob"):
246 return gob.NewDecoder(resp.Body)
247 case ct == "text/html" || ct == "text/plain" ||
248 strings.HasSuffix(ct, "+html") || strings.HasSuffix(ct, "+txt"):
249 return newTextDecoder(resp.Body, ct)
250 default:
251 return json.NewDecoder(resp.Body)
252 }
253}
254
255// ErrorEncoder returns an encoder that encodes errors returned by service
256// methods. The default encoder checks whether the error is a goa ServiceError

Callers 1

TestResponseDecoderFunction · 0.70

Calls 2

newTextDecoderFunction · 0.85
GetMethod · 0.45

Tested by 1

TestResponseDecoderFunction · 0.56