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:
parent
879d613b46
commit
1d6a9c0950
1 changed files with 46 additions and 0 deletions
46
src/api/test.go
Normal file
46
src/api/test.go
Normal 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, ""
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue