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

src/parse_request.go: use api.ApiArguments instead of arguments struct

This commit is contained in:
Henrik Hautakoski 2022-10-25 17:46:32 +02:00
parent d8c8c14edc
commit b41fb21f6a
No known key found for this signature in database
GPG key ID: 608414D93E862CCD

View file

@ -8,32 +8,26 @@ import (
"github.com/eosswedenorg/eosio-api-healthcheck/src/api"
)
type arguments struct {
url string
host string
num_blocks int
}
func ParseArguments(args []string) api.ApiArguments {
func ParseArguments(args []string) arguments {
a := arguments{
num_blocks: 10,
a := api.ApiArguments{
NumBlocks: 10,
}
// 1. url (scheme + ip/domain + port)
a.url = args[0]
a.Url = args[0]
// 2. num blocks
if len(args) > 1 {
num, err := strconv.ParseInt(args[1], 10, 32)
if err == nil {
a.num_blocks = int(num)
a.NumBlocks = int(num)
}
}
// 3. Host
if len(args) > 2 {
a.host = args[2]
a.Host = args[2]
}
return a
@ -53,13 +47,13 @@ func ParseRequest(request string) (api.ApiInterface, error) {
switch p[0] {
case "v1":
return api.NewEosioV1(a.url, a.host, float64(a.num_blocks / 2)), nil
return api.NewEosioV1(a.Url, a.Host, float64(a.NumBlocks / 2)), nil
case "v2":
return api.NewEosioV2(a.url, a.host, int64(a.num_blocks)), nil
return api.NewEosioV2(a.Url, a.Host, int64(a.NumBlocks)), nil
case "contract":
return api.NewEosioContract(a.url, float64(a.num_blocks / 2)), nil
return api.NewEosioContract(a.Url, float64(a.NumBlocks / 2)), nil
case "debug":
return api.NewDebugApi(a.url), nil
return api.NewDebugApi(a.Url), nil
}
return nil, fmt.Errorf("invalid API '%s'", p[0])