-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_config.go
59 lines (50 loc) · 1.18 KB
/
client_config.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
package exaroton
import (
"context"
"pkg.icikowski.pl/exaroton/model"
)
type configClient struct {
*baseClient
serverID string
path string
}
func newConfigClient(base *baseClient, serverID, path string) ConfigAPI {
return &configClient{
baseClient: base,
serverID: serverID,
path: path,
}
}
// GetConfig implements ConfigAPI.
func (c *configClient) GetConfig(ctx context.Context) (model.ConfigOptions, *RawResponse[model.ConfigOptions], error) {
resp, err := c.do(c.rb.buildConfigGetRequest(
ctx,
c.serverID,
c.path,
))
if err != nil {
return nil, nil, err
}
rawResp, err := decodeRawResponse[model.ConfigOptions](resp)
if err != nil {
return nil, rawResp, err
}
return *rawResp.Data, rawResp, nil
}
// SetConfig implements ConfigAPI.
func (c *configClient) SetConfig(ctx context.Context, opts model.ConfigValues) (model.ConfigOptions, *RawResponse[model.ConfigOptions], error) {
resp, err := c.do(c.rb.buildConfigPostRequest(
ctx,
c.serverID,
c.path,
opts,
))
if err != nil {
return nil, nil, err
}
rawResp, err := decodeRawResponse[model.ConfigOptions](resp)
if err != nil {
return nil, rawResp, err
}
return *rawResp.Data, rawResp, nil
}