MustEncodeWithParser encode with the registered parserType,
(w io.Writer, i interface{})
| 3171 | |
| 3172 | // MustEncodeWithParser encode with the registered parserType, |
| 3173 | func MustEncodeWithParser(w io.Writer, i interface{}) { |
| 3174 | rw, rwOk := w.(http.ResponseWriter) |
| 3175 | if rwOk { |
| 3176 | h := rw.Header() |
| 3177 | if h != nil { |
| 3178 | h.Set("Cache-Control", "no-cache") |
| 3179 | if h.Get("Content-type") == "" { |
| 3180 | h.Set("Content-type", "application/json") |
| 3181 | } |
| 3182 | } |
| 3183 | } |
| 3184 | var err error |
| 3185 | if JSONImpl != nil { |
| 3186 | err = JSONImpl.Encode(w, i) |
| 3187 | } else { |
| 3188 | err = fmt.Errorf("bleve: MustEncodeWithParser fails as no custom parser found") |
| 3189 | } |
| 3190 | if err != nil { |
| 3191 | if rwOk { |
| 3192 | crw, ok := rw.(*rest.CountResponseWriter) |
| 3193 | if ok && crw.Wrote { |
| 3194 | return |
| 3195 | } |
| 3196 | rest.PropagateError(rw, nil, |
| 3197 | fmt.Sprintf("rest: custom JSON: %s encode, err: %v", |
| 3198 | JSONImpl.GetParserType(), err), http.StatusInternalServerError) |
| 3199 | } |
| 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | // ----------------------------------------------------------------------------- |
| 3204 |
no test coverage detected