mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-07-03 11:53:43 +02:00
src/parse_request.go: use api.ApiArguments instead of arguments struct
This commit is contained in:
parent
d8c8c14edc
commit
b41fb21f6a
1 changed files with 10 additions and 16 deletions
|
|
@ -8,32 +8,26 @@ import (
|
||||||
"github.com/eosswedenorg/eosio-api-healthcheck/src/api"
|
"github.com/eosswedenorg/eosio-api-healthcheck/src/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
type arguments struct {
|
func ParseArguments(args []string) api.ApiArguments {
|
||||||
url string
|
|
||||||
host string
|
|
||||||
num_blocks int
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParseArguments(args []string) arguments {
|
a := api.ApiArguments{
|
||||||
|
NumBlocks: 10,
|
||||||
a := arguments{
|
|
||||||
num_blocks: 10,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. url (scheme + ip/domain + port)
|
// 1. url (scheme + ip/domain + port)
|
||||||
a.url = args[0]
|
a.Url = args[0]
|
||||||
|
|
||||||
// 2. num blocks
|
// 2. num blocks
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
num, err := strconv.ParseInt(args[1], 10, 32)
|
num, err := strconv.ParseInt(args[1], 10, 32)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
a.num_blocks = int(num)
|
a.NumBlocks = int(num)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Host
|
// 3. Host
|
||||||
if len(args) > 2 {
|
if len(args) > 2 {
|
||||||
a.host = args[2]
|
a.Host = args[2]
|
||||||
}
|
}
|
||||||
|
|
||||||
return a
|
return a
|
||||||
|
|
@ -53,13 +47,13 @@ func ParseRequest(request string) (api.ApiInterface, error) {
|
||||||
|
|
||||||
switch p[0] {
|
switch p[0] {
|
||||||
case "v1":
|
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":
|
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":
|
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":
|
case "debug":
|
||||||
return api.NewDebugApi(a.url), nil
|
return api.NewDebugApi(a.Url), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("invalid API '%s'", p[0])
|
return nil, fmt.Errorf("invalid API '%s'", p[0])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue