-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
66 lines (59 loc) · 1.86 KB
/
client.go
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
56
57
58
59
60
61
62
63
64
65
66
package sdk
import (
"github.com/bianjieai/avata-sdk-go/v3/configs"
"github.com/bianjieai/avata-sdk-go/v3/models"
"github.com/bianjieai/avata-sdk-go/v3/services"
"github.com/bianjieai/avata-sdk-go/v3/utils"
)
type AvataClient struct {
Account services.AccountService
Tx services.TxService
NFT services.NFTService
Record services.RecordService
Order services.OrderService
NS services.NSService
Contract services.ContractService
MT services.MTService
Users services.UsersService
Resolves services.ResolvesService
}
func NewClient(domain, apiKey, apiSecret string, options ...configs.Options) *AvataClient {
// 校验必填参数
checkBaseParams(domain, apiKey, apiSecret)
// 设置默认配置
cfg := configs.SetDefaultConfig()
// 遍历调用函数,调整配置
for _, option := range options {
option(cfg)
}
baseParams := models.BaseParams{
Domain: domain,
APIKey: apiKey,
APISecret: apiSecret,
}
// 初始化
httpClient := utils.NewHttpClient(cfg.HttpTimeout, baseParams)
return &AvataClient{
Account: services.NewAccountService(cfg.Logger, httpClient),
Tx: services.NewTxService(cfg.Logger, httpClient),
NFT: services.NewNFTService(cfg.Logger, httpClient),
Record: services.NewRecordService(cfg.Logger, httpClient),
Order: services.NewOrderService(cfg.Logger, httpClient),
NS: services.NewNSService(cfg.Logger, httpClient),
Contract: services.NewContractService(cfg.Logger, httpClient),
MT: services.NewMTService(cfg.Logger, httpClient),
Users: services.NewUsersService(cfg.Logger, httpClient),
Resolves: services.NewResolvesService(cfg.Logger, httpClient),
}
}
func checkBaseParams(domain, apiKey, apiSecret string) {
if domain == "" {
panic(models.ErrDomain)
}
if apiKey == "" {
panic(models.ErrAPIKey)
}
if apiSecret == "" {
panic(models.ErrAPISecret)
}
}