-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.go
More file actions
55 lines (47 loc) · 1.31 KB
/
client.go
File metadata and controls
55 lines (47 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package gocodex
import (
"github.com/pkg/errors"
"github.com/codexnetwork/codex-go/config"
eosforceApi "github.com/codexnetwork/codex-go/eosforce"
eosioApi "github.com/codexnetwork/codex-go/eosio"
forceioApi "github.com/codexnetwork/codex-go/forceio"
"github.com/codexnetwork/codex-go/types"
)
// Client client to forceio chain
type Client struct {
api types.ClientInterface
typ types.ClientType
}
// NewClientAPI create client to chain by typ
func NewClientAPI(typ types.ClientType, cfg *config.ConfigData) (types.ClientInterface, error) {
var res types.ClientInterface
switch typ {
case types.FORCEIO:
res = &forceioApi.API{}
case types.EOSIO:
res = &eosioApi.API{}
case types.ENU:
res = &eosioApi.API{}
case types.EOSForce:
res = &eosforceApi.API{}
default:
return nil, errors.New("unsupported api type")
}
err := res.Init(cfg)
if err != nil {
return nil, err
}
return res, nil
}
// NewClient create client by config data
func NewClient(typ types.ClientType, cfg *config.ConfigData) (types.ClientInterface, error) {
return NewClientAPI(typ, cfg)
}
// NewClientFromFile create client by config file
func NewClientFromFile(typ types.ClientType, path string) (types.ClientInterface, error) {
cfg, err := config.LoadCfgFromFile(path)
if err != nil {
return nil, err
}
return NewClient(typ, cfg)
}