// jsonStatusResponse writes to the response writer
// JSON-encoded StatusResponse based on the provided status code.
18856
func jsonStatusResponse(w http.ResponseWriter, code int) {
	w.Header().Set("Content-Type", jsonContentType)
	w.WriteHeader(code)
	err := json.NewEncoder(w).Encode(StatusResponse{
		Message: http.StatusText(code),
		Code:    code,
	})
	if err != nil {
		log.Error("chunk explorer: json status response", "err", err)
	}
}
1232706
func (r Response) StatusCode() int {
	if 0 == r.statusCode {
		// no status code has been written yet; assume OK
		return http.StatusOK
	}
	return r.statusCode
}
248336
func JSON(rw http.ResponseWriter, status int, v interface{}) error {
	if pb, ok := v.(proto.Message); ok {
		return Proto(rw, status, pb)
	}

	b, err := json.MarshalIndent(v, "", "  ")
	if err != nil {
		return err
	}
	rw.Header().Add("Content-Type", "application/json")
	rw.WriteHeader(status)
	_, err = rw.Write(b)
	return err
}
1212325
func RestHandleResponse(context *gin.Context, body interface{}, err error) {
	if err == nil {
		context.JSON(200, body)
	} else {
		context.String(400, err.Error())
	}
}
1330150
func ReadJSONResponse(resp *http.Response, v interface{}) error {
	defer resp.Body.Close()

	switch {
	case resp.StatusCode < 200, resp.StatusCode > 299:
		return NewResponseErrorf(resp, "Invalid status code: %d", resp.StatusCode)
	case v == nil:
		return nil
	default:
		if err := json.NewDecoder(resp.Body).Decode(v); err != nil {
			return NewResponseError(resp, err.Error())
		}
	}

	return nil
}
769997
func SendHTTPStatusAndJSON(w http.ResponseWriter, statusCode int, response interface{}) {
	body, err := json.Marshal(response)
	if err != nil {
		http.Error(w, errors.Annotatef(err, "cannot marshal JSON result %#v", response).Error(), 504)
		return
	}

	if statusCode == http.StatusUnauthorized {
		w.Header().Set("WWW-Authenticate", `Basic realm="juju"`)
	}
	w.Header().Set("Content-Type", params.ContentTypeJSON)
	w.Header().Set("Content-Length", fmt.Sprint(len(body)))
	w.WriteHeader(statusCode)
	w.Write(body)
}
180084
func WriteJSON(w http.ResponseWriter, value interface{}, status int) error {
	return jsonResponseEncoder.writeResponseJSON(w, value, status)
}
17458
func (h *Handler) handleGetStatus(w http.ResponseWriter, r *http.Request) {
	if !validHeaderAcceptJSON(r.Header) {
		http.Error(w, "JSON only acceptable response", http.StatusNotAcceptable)
		return
	}
	status := getStatusResponse{
		State:   h.api.State(),
		Nodes:   h.api.Hosts(r.Context()),
		LocalID: h.api.Node().ID,
	}
	if err := json.NewEncoder(w).Encode(status); err != nil {
		h.logger.Printf("write status response error: %s", err)
	}
}
194466
func (u serviceStatusMessage) JSON() string {
	switch u.Service {
	case "on":
		u.Status = "success"
	case "off":
		u.Status = "failure"
	}

	statusJSONBytes, e := json.MarshalIndent(u, "", " ")
	fatalIf(probe.NewError(e), "Unable to marshal into JSON.")

	return string(statusJSONBytes)
}
791666
func WriteErrorResponse(statusCode int, message string, w http.ResponseWriter) {
	var errstr []string

	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(statusCode)
	errstr = append(errstr, http.StatusText(statusCode))
	resp := ErrorResponse{
		Status:  http.StatusText(statusCode),
		Message: message,
		Errors:  errstr,
	}
	json.NewEncoder(w).Encode(resp)
}
362944
func writeJSON(w *rest.ResponseWriter, v interface{}, code int) {
	w.Header().Set("content-type", "application/json")
	w.WriteHeader(code)
	err := w.WriteJson(v)
	if err != nil {
		panic(err)
	}
}
251478
func Status(status int) {
	if r, ok := responseDefinition(); ok {
		r.Status = status
	}
}
842854
func (o *GetStatusReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {

	case 200:
		result := NewGetStatusOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil

	default:
		return nil, runtime.NewAPIError("unknown error", response, response.Code())
	}
}
597938
func (r Result) StatusCode(statusCode *int) Result {
	*statusCode = r.statusCode
	return r
}
394139
func WriteRawJSON(statusCode int, object interface{}, w http.ResponseWriter) {
	output, err := json.MarshalIndent(object, "", "  ")
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(statusCode)
	w.Write(output)
}
648509
func (c *C) JSON(status int, v interface{}) {
	c.Writer.Header().Set(contentType, "application/json; charset=UTF-8")
	c.Writer.WriteHeader(status)
	if v == nil {
		return
	}

	buf := bufPool.Get()
	defer bufPool.Put(buf)

	if err := json.NewEncoder(buf).Encode(v); err != nil {
		panic(err)
	}

	c.Writer.Write(buf.Bytes())
}
1294274
func (r *ResponseMatcher) Status(code int) *ResponseMatcher {
	r.mux.mu.Lock()
	defer r.mux.mu.Unlock()
	r.minStatus = code
	r.maxStatus = code
	return r
}