From 4811a72d800e9a31112624ed47f9973aae6c460c Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Thu, 24 Mar 2016 11:26:07 -0700 Subject: [PATCH] Added some constants in the api for check health statuses --- api/agent.go | 12 ++++++------ api/health.go | 22 ++++++++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/api/agent.go b/api/agent.go index 54d30cac04..67855c67fb 100644 --- a/api/agent.go +++ b/api/agent.go @@ -257,12 +257,12 @@ type checkUpdate struct { // required to use this API). func (a *Agent) UpdateTTL(checkID, output, status string) error { switch status { - case "pass", "passing": - status = "passing" - case "warn", "warning": - status = "warning" - case "fail", "critical": - status = "critical" + case "pass", HealthPassing: + status = HealthPassing + case "warn", HealthWarning: + status = HealthWarning + case "fail", HealthCritical: + status = HealthCritical default: return fmt.Errorf("Invalid status: %s", status) } diff --git a/api/health.go b/api/health.go index 1a273e087c..5bb403f554 100644 --- a/api/health.go +++ b/api/health.go @@ -4,6 +4,16 @@ import ( "fmt" ) +const ( + // HealthAny is special, and is used as a wild card, + // not as a specific state. + HealthAny = "any" + HealthUnknown = "unknown" + HealthPassing = "passing" + HealthWarning = "warning" + HealthCritical = "critical" +) + // HealthCheck is used to represent a single check type HealthCheck struct { Node string @@ -85,7 +95,7 @@ func (h *Health) Service(service, tag string, passingOnly bool, q *QueryOptions) r.params.Set("tag", tag) } if passingOnly { - r.params.Set("passing", "1") + r.params.Set(HealthPassing, "1") } rtt, resp, err := requireOK(h.c.doRequest(r)) if err != nil { @@ -108,11 +118,11 @@ func (h *Health) Service(service, tag string, passingOnly bool, q *QueryOptions) // The wildcard "any" state can also be used for all checks. func (h *Health) State(state string, q *QueryOptions) ([]*HealthCheck, *QueryMeta, error) { switch state { - case "any": - case "warning": - case "critical": - case "passing": - case "unknown": + case HealthAny: + case HealthWarning: + case HealthCritical: + case HealthPassing: + case HealthUnknown: default: return nil, nil, fmt.Errorf("Unsupported state: %v", state) }