From 4a73480603c56c5a866857eb16b16c1d04ecaa97 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 7 Feb 2020 07:14:23 +0100 Subject: [PATCH] server.go: rename "v2" parameter to "version" and make it a string. --- README.md | 12 ++++++------ server.go | 9 +++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 70cf94b..b31df68 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,12 @@ The protocol is simple and has 4 rules. The following parameters are supported in a request and are ordered from first to last below: -| # | Name | Required | Description | -| - | ---------- | -------- | ---------------------------------------------------------------------- | -| 1 | Host | Yes | IP/Hostname to the api. | -| 2 | Port | No | Port number to the api (default `80`) | -| 3 | num_blocks | No | Number of blocks the api can drift before reported `down` (default 10) | -| 4 | hyperion | No | `1` if hyperion healthcheck should be used (default `0`) | +| # | Name | Required | Description | +| - | ---------- | -------- | ----------------------------------------------------------------------------- | +| 1 | Host | Yes | IP/Hostname to the api. | +| 2 | Port | No | Port number to the api (default `80`) | +| 3 | num_blocks | No | Number of blocks the api can drift before reported `down` (default 10) | +| 4 | version | No | API Version to check against, `v1` = standard, `v2` = Hyperion (default `v1`) | ### Response diff --git a/server.go b/server.go index 29700e2..b5db636 100644 --- a/server.go +++ b/server.go @@ -118,7 +118,7 @@ func main() { var host string var port int = 80 var block_time int = 10 - var v2 bool = false; + var version string = "v1" // Parse host + port. split := strings.Split(strings.TrimSpace(message), ":") @@ -137,17 +137,14 @@ func main() { } } if len(split) > 3 { - p, err := strconv.ParseInt(split[3], 10, 32) - if err == nil { - v2 = p != 0; - } + version = split[3] } // Check api. var status haproxy.HealthCheckStatus var msg string - if v2 { + if version == "v2" { status, msg = check_api_v2(host, port, int64(block_time / 2)) } else { status, msg = check_api(host, port, float64(block_time))