-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_credit_pool.go
71 lines (60 loc) · 1.55 KB
/
client_credit_pool.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
67
68
69
70
71
package exaroton
import (
"context"
"pkg.icikowski.pl/exaroton/model"
)
type creditPoolClient struct {
*baseClient
poolID string
}
func newCreditPoolClient(base *baseClient, poolID string) CreditPoolAPI {
return &creditPoolClient{
baseClient: base,
poolID: poolID,
}
}
// GetCreditPool implements CreditPoolAPI.
func (c *creditPoolClient) GetCreditPool(ctx context.Context) (*model.CreditPool, *RawResponse[model.CreditPool], error) {
resp, err := c.do(c.rb.buildCreditPoolGetRequest(
ctx,
c.poolID,
))
if err != nil {
return nil, nil, err
}
rawResp, err := decodeRawResponse[model.CreditPool](resp)
if err != nil {
return nil, rawResp, err
}
return rawResp.Data, rawResp, nil
}
// GetServers implements CreditPoolAPI.
func (c *creditPoolClient) GetServers(ctx context.Context) (model.Servers, *RawResponse[model.Servers], error) {
resp, err := c.do(c.rb.buildCreditPoolServersGetRequest(
ctx,
c.poolID,
))
if err != nil {
return nil, nil, err
}
rawResp, err := decodeRawResponse[model.Servers](resp)
if err != nil {
return nil, rawResp, err
}
return *rawResp.Data, rawResp, nil
}
// GetMembers implements CreditPoolAPI.
func (c *creditPoolClient) GetMembers(ctx context.Context) (model.CreditPoolMembers, *RawResponse[model.CreditPoolMembers], error) {
resp, err := c.do(c.rb.buildCreditPoolMembersGetRequest(
ctx,
c.poolID,
))
if err != nil {
return nil, nil, err
}
rawResp, err := decodeRawResponse[model.CreditPoolMembers](resp)
if err != nil {
return nil, rawResp, err
}
return *rawResp.Data, rawResp, nil
}