mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-06-18 05:00:03 +02:00
Fix code formatting
This commit is contained in:
parent
b0e5b455ca
commit
adb1ad3c6d
21 changed files with 884 additions and 950 deletions
|
|
@ -1,60 +1,58 @@
|
|||
|
||||
package internal
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"github.com/eosswedenorg/eosio-api-healthcheck/internal/api"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/eosswedenorg/eosio-api-healthcheck/internal/api"
|
||||
)
|
||||
|
||||
func ParseArguments(args []string) api.ApiArguments {
|
||||
a := api.ApiArguments{
|
||||
NumBlocks: 10,
|
||||
}
|
||||
|
||||
a := api.ApiArguments{
|
||||
NumBlocks: 10,
|
||||
}
|
||||
// 1. url (scheme + ip/domain + port)
|
||||
a.Url = args[0]
|
||||
|
||||
// 1. url (scheme + ip/domain + port)
|
||||
a.Url = args[0]
|
||||
// 2. num blocks
|
||||
if len(args) > 1 {
|
||||
num, err := strconv.ParseInt(args[1], 10, 32)
|
||||
if err == nil {
|
||||
a.NumBlocks = int(num)
|
||||
}
|
||||
}
|
||||
|
||||
// 2. num blocks
|
||||
if len(args) > 1 {
|
||||
num, err := strconv.ParseInt(args[1], 10, 32)
|
||||
if err == nil {
|
||||
a.NumBlocks = int(num)
|
||||
}
|
||||
}
|
||||
// 3. Host
|
||||
if len(args) > 2 {
|
||||
a.Host = args[2]
|
||||
}
|
||||
|
||||
// 3. Host
|
||||
if len(args) > 2 {
|
||||
a.Host = args[2]
|
||||
}
|
||||
|
||||
return a
|
||||
return a
|
||||
}
|
||||
|
||||
func ParseRequest(request string) (api.ApiInterface, error) {
|
||||
factories := map[string]api.Factory{
|
||||
"v1": api.EosioV1Factory,
|
||||
"v2": api.EosioV2Factory,
|
||||
"contract": api.EosioContractFactory,
|
||||
"debug": api.DebugApiFactory,
|
||||
}
|
||||
|
||||
factories := map[string]api.Factory{
|
||||
"v1": api.EosioV1Factory,
|
||||
"v2": api.EosioV2Factory,
|
||||
"contract": api.EosioContractFactory,
|
||||
"debug": api.DebugApiFactory,
|
||||
}
|
||||
// Parse arguments.
|
||||
// -------------------
|
||||
p := strings.Split(strings.TrimSpace(request), "|")
|
||||
|
||||
// Parse arguments.
|
||||
// -------------------
|
||||
p := strings.Split(strings.TrimSpace(request), "|")
|
||||
if len(p) < 2 {
|
||||
return nil, fmt.Errorf("invalid number of parameters in agent request")
|
||||
}
|
||||
|
||||
if len(p) < 2 {
|
||||
return nil, fmt.Errorf("invalid number of parameters in agent request")
|
||||
}
|
||||
a := ParseArguments(p[1:])
|
||||
|
||||
a := ParseArguments(p[1:])
|
||||
if factory, ok := factories[p[0]]; ok {
|
||||
return factory(a), nil
|
||||
}
|
||||
|
||||
if factory, ok := factories[p[0]]; ok {
|
||||
return factory(a), 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