MCPcopy
hub / github.com/elastic/go-elasticsearch / Health

Function Health

_examples/cloudfunction/function.go:60–86  ·  view source on GitHub ↗

Health returns the status of the cluster (red, yellow, green).

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

58
59// Health returns the status of the cluster (red, yellow, green).
60func Health(w http.ResponseWriter, r *http.Request) {
61 var j map[string]interface{}
62
63 res, err := ES.Cluster.Health()
64 if err != nil {
65 log.Printf("Error getting response from Elasticsearch: %s", err)
66 http.Error(w, `{"status" : "error"}`, http.StatusBadGateway)
67 return
68 }
69 defer res.Body.Close()
70
71 if res.IsError() {
72 log.Printf("HTTP response error: %s", res.Status())
73 http.Error(w, `{"status" : "error"}`, http.StatusBadGateway)
74 return
75 }
76
77 if err := json.NewDecoder(res.Body).Decode(&j); err != nil {
78 log.Printf("Error parsing the HTTP response body: %s", err)
79 http.Error(w, `{"status" : "error"}`, http.StatusInternalServerError)
80 return
81 } else {
82 w.Header().Set("Content-Type", "application/json")
83 w.WriteHeader(http.StatusOK)
84 fmt.Fprintf(w, `{"status":%q}`, j["status"].(string))
85 }
86}

Callers

nothing calls this directly

Calls 8

PrintfMethod · 0.80
IsErrorMethod · 0.80
CloseMethod · 0.65
HealthMethod · 0.45
ErrorMethod · 0.45
StatusMethod · 0.45
SetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected