-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.go
More file actions
61 lines (49 loc) · 1.2 KB
/
config.go
File metadata and controls
61 lines (49 loc) · 1.2 KB
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
package config
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
deis "github.com/deis/controller-sdk-go"
"github.com/deis/controller-sdk-go/api"
)
// List lists an app's config.
func List(c *deis.Client, app string) (api.Config, error) {
u := fmt.Sprintf("/v2/apps/%s/config/", app)
res, err := c.Request("GET", u, nil)
if err != nil {
return api.Config{}, err
}
// Fix json.Decoder bug in <go1.7
defer func() {
io.Copy(ioutil.Discard, res.Body)
res.Body.Close()
}()
config := api.Config{}
if err = json.NewDecoder(res.Body).Decode(&config); err != nil {
return api.Config{}, err
}
return config, nil
}
// Set sets an app's config variables.
func Set(c *deis.Client, app string, config api.Config) (api.Config, error) {
body, err := json.Marshal(config)
if err != nil {
return api.Config{}, err
}
u := fmt.Sprintf("/v2/apps/%s/config/", app)
res, err := c.Request("POST", u, body)
if err != nil {
return api.Config{}, err
}
// Fix json.Decoder bug in <go1.7
defer func() {
io.Copy(ioutil.Discard, res.Body)
res.Body.Close()
}()
newConfig := api.Config{}
if err = json.NewDecoder(res.Body).Decode(&newConfig); err != nil {
return api.Config{}, err
}
return newConfig, nil
}