1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-07-04 12:03:43 +02:00

src/server.go: Add backward support for the old request format.

This commit is contained in:
Henrik Hautakoski 2022-05-17 18:52:17 +02:00
parent 1912ef1790
commit 32619b293f
No known key found for this signature in database
GPG key ID: 608414D93E862CCD

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"strconv" "strconv"
"github.com/eosswedenorg/eosio-api-healthcheck/src/utils"
"github.com/eosswedenorg/eosio-api-healthcheck/src/api" "github.com/eosswedenorg/eosio-api-healthcheck/src/api"
"github.com/eosswedenorg-go/eosapi" "github.com/eosswedenorg-go/eosapi"
"github.com/eosswedenorg-go/haproxy/agentcheck" "github.com/eosswedenorg-go/haproxy/agentcheck"
@ -60,23 +61,63 @@ func onTcpMessage(c *tcp_server.Client, args string) {
return return
} }
// 1. Api // Old format: <url> <version> <api> <block_time>
a.api = split[0] if utils.IsUrl(split[0]) {
// 2. url (scheme + ip/domain + port) logger.Warn("Deprecated format. Please change to the new format: <api>|<url>[|<block_time>|<host>]")
a.url = split[1]
// 3. Block time. // 1. url (scheme + ip/domain + port)
if len(split) > 2 { a.url = split[0]
num, err := strconv.ParseInt(split[2], 10, 32)
if err == nil { // 2. api
a.block_time = int(num) if len(split) > 1 {
a.api = split[1]
} }
}
// 4. Host // 3. Block time
if len(split) > 3 { if len(split) > 2 {
a.host = split[3] num, err := strconv.ParseInt(split[2], 10, 32)
if err == nil {
a.block_time = int(num)
}
}
// 4. Host
if len(split) > 3 {
a.host = split[3]
}
} else {
if len(split) < 2 {
msg := "Invalid number of parameters in agent request"
logger.Warn("Agent request error", "message", msg, "args", split)
resp := agentcheck.NewStatusMessageResponse(agentcheck.Failed, msg)
c.WriteString(resp.String())
c.Close()
return
}
// 1. Api
a.api = split[0]
// 2. url (scheme + ip/domain + port)
a.url = split[1]
// 3. Block time.
if len(split) > 2 {
num, err := strconv.ParseInt(split[2], 10, 32)
if err == nil {
a.block_time = int(num)
}
}
// 4. Host
if len(split) > 3 {
a.host = split[3]
}
} }
// Check api. // Check api.