1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-06-18 05:00:03 +02:00

Adding src/api/test.go

This commit is contained in:
Henrik Hautakoski 2022-08-12 17:56:59 +02:00
parent 879d613b46
commit 1d6a9c0950
No known key found for this signature in database
GPG key ID: 608414D93E862CCD

46
src/api/test.go Normal file
View file

@ -0,0 +1,46 @@
package api
import (
"strings"
"github.com/eosswedenorg-go/haproxy/agentcheck"
)
type TestApi struct {
response agentcheck.Response
}
func parseResponse(resp string) (agentcheck.Response, error) {
parts := strings.SplitN(resp, "#", 2)
// Status with message
if len(parts) > 1 {
rtype := agentcheck.StatusMessageResponseType(parts[0])
return agentcheck.NewStatusMessageResponse(rtype, parts[1]), nil
}
// Only status.
rtype := agentcheck.StatusResponseType(parts[0])
return agentcheck.NewStatusResponse(rtype), nil
}
func NewTestApi(response string) TestApi {
resp, _ := parseResponse(response)
return TestApi{
response: resp,
}
}
func (t TestApi) LogInfo() LogParams {
return LogParams{
"type", "TestApi",
"response", t.response,
}
}
func (t TestApi) Call() (agentcheck.Response, string) {
return t.response, ""
}