-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig.go
62 lines (46 loc) · 1.12 KB
/
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
60
61
62
package coreclient
import (
"bytes"
"encoding/json"
"github.com/datarhei/core-client-go/v16/api"
)
type configVersion struct {
Config struct {
Version int64 `json:"version"`
} `json:"config"`
}
func (r *restclient) Config() (int64, api.Config, error) {
version := configVersion{}
data, err := r.call("GET", "/v3/config", "", nil)
if err != nil {
return 0, api.Config{}, err
}
if err := json.Unmarshal(data, &version); err != nil {
return 0, api.Config{}, err
}
config := api.Config{}
if err := json.Unmarshal(data, &config); err != nil {
return 0, api.Config{}, err
}
return version.Config.Version, config, nil
}
func (r *restclient) ConfigSet(config interface{}) error {
var buf bytes.Buffer
e := json.NewEncoder(&buf)
e.Encode(config)
_, err := r.call("PUT", "/v3/config", "application/json", &buf)
if e, ok := err.(api.Error); ok {
if e.Code == 409 {
ce := api.ConfigError{}
if err := json.Unmarshal(e.Body, &ce); err != nil {
return e
}
return ce
}
}
return err
}
func (r *restclient) ConfigReload() error {
_, err := r.call("GET", "/v3/config/reload", "", nil)
return err
}