MCPcopy Create free account
hub / github.com/couchbase/cbft / MustEncodeWithParser

Function MustEncodeWithParser

pindex_bleve.go:3173–3201  ·  view source on GitHub ↗

MustEncodeWithParser encode with the registered parserType,

(w io.Writer, i interface{})

Source from the content-addressed store, hash-verified

3171
3172// MustEncodeWithParser encode with the registered parserType,
3173func 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

Callers 1

mustEncodeFunction · 0.85

Calls 4

HeaderMethod · 0.80
GetMethod · 0.80
EncodeMethod · 0.80
GetParserTypeMethod · 0.80

Tested by

no test coverage detected