mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-06-18 05:00:03 +02:00
internal/server/parse_request.go: move api factory code into its own function in api package: api.Make()
This commit is contained in:
parent
1fb48800a1
commit
8feca959d4
2 changed files with 22 additions and 13 deletions
21
internal/api/make.go
Normal file
21
internal/api/make.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func Make(name string, args ApiArguments) (ApiInterface, error) {
|
||||
factories := map[string]Factory{
|
||||
"v1": EosioV1Factory,
|
||||
"v2": EosioV2Factory,
|
||||
"contract": AtomicAssetFactory,
|
||||
"atomic": AtomicAssetFactory,
|
||||
"debug": DebugApiFactory,
|
||||
}
|
||||
|
||||
if factory, ok := factories[name]; ok {
|
||||
return factory(args), nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("invalid API '%s'", name)
|
||||
}
|
||||
|
|
@ -33,14 +33,6 @@ func ParseArguments(args []string) api.ApiArguments {
|
|||
}
|
||||
|
||||
func ParseRequest(request string) (api.ApiInterface, error) {
|
||||
factories := map[string]api.Factory{
|
||||
"v1": api.EosioV1Factory,
|
||||
"v2": api.EosioV2Factory,
|
||||
"contract": api.AtomicAssetFactory,
|
||||
"atomic": api.AtomicAssetFactory,
|
||||
"debug": api.DebugApiFactory,
|
||||
}
|
||||
|
||||
// Parse arguments.
|
||||
// -------------------
|
||||
p := strings.Split(strings.TrimSpace(request), "|")
|
||||
|
|
@ -51,9 +43,5 @@ func ParseRequest(request string) (api.ApiInterface, error) {
|
|||
|
||||
a := ParseArguments(p[1:])
|
||||
|
||||
if factory, ok := factories[p[0]]; ok {
|
||||
return factory(a), nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("invalid API '%s'", p[0])
|
||||
return api.Make(p[0], a)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue