MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / ReadJSONFromMIME

Function ReadJSONFromMIME

rest/multipart.go:41–52  ·  view source on GitHub ↗

ReadJSONFromMIME parses a JSON MIME body, unmarshalling it into "into". Closes the input io.ReadCloser once done.

(headers http.Header, input io.ReadCloser, into interface{})

Source from the content-addressed store, hash-verified

39// ReadJSONFromMIME parses a JSON MIME body, unmarshalling it into "into".
40// Closes the input io.ReadCloser once done.
41func ReadJSONFromMIME(headers http.Header, input io.ReadCloser, into interface{}) error {
42 err := ReadJSONFromMIMERawErr(headers, input, into)
43 if err != nil {
44 err = base.WrapJSONUnknownFieldErr(err)
45 if errors.Cause(err) == base.ErrUnknownField {
46 err = base.HTTPErrorf(http.StatusBadRequest, "JSON Unknown Field: %s", err.Error())
47 } else {
48 err = base.HTTPErrorf(http.StatusBadRequest, "Bad JSON: %s", err.Error())
49 }
50 }
51 return err
52}
53
54func ReadJSONFromMIMERawErr(headers http.Header, input io.ReadCloser, into interface{}) error {
55 input, err := processContentEncoding(headers, input, "application/json")

Callers 3

ReadMultipartDocumentFunction · 0.85
readJSONIntoMethod · 0.85
TestReadJSONFromMIMEFunction · 0.85

Calls 4

WrapJSONUnknownFieldErrFunction · 0.92
HTTPErrorfFunction · 0.92
ReadJSONFromMIMERawErrFunction · 0.85
ErrorMethod · 0.45

Tested by 1

TestReadJSONFromMIMEFunction · 0.68