-
Notifications
You must be signed in to change notification settings - Fork 26
/
client.go
57 lines (46 loc) · 1.41 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
package rpc
import (
// RPC
"github.com/go-steem/rpc/apis/database"
"github.com/go-steem/rpc/apis/follow"
"github.com/go-steem/rpc/apis/login"
"github.com/go-steem/rpc/apis/networkbroadcast"
"github.com/go-steem/rpc/interfaces"
)
// Client can be used to access Steem remote APIs.
//
// There is a public field for every Steem API available,
// e.g. Client.Database corresponds to database_api.
type Client struct {
cc interfaces.CallCloser
// Login represents login_api.
Login *login.API
// Database represents database_api.
Database *database.API
// Follow represents follow_api.
Follow *follow.API
// NetworkBroadcast represents network_broadcast_api.
NetworkBroadcast *networkbroadcast.API
}
// NewClient creates a new RPC client that use the given CallCloser internally.
func NewClient(cc interfaces.CallCloser) (*Client, error) {
client := &Client{cc: cc}
client.Login = login.NewAPI(client.cc)
client.Database = database.NewAPI(client.cc)
followAPI, err := follow.NewAPI(client.cc)
if err != nil {
return nil, err
}
client.Follow = followAPI
networkBroadcastAPI, err := networkbroadcast.NewAPI(client.cc)
if err != nil {
return nil, err
}
client.NetworkBroadcast = networkBroadcastAPI
return client, nil
}
// Close should be used to close the client when no longer needed.
// It simply calls Close() on the underlying CallCloser.
func (client *Client) Close() error {
return client.cc.Close()
}