forked from fastly/go-fastly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.go
77 lines (63 loc) · 1.92 KB
/
settings.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
72
73
74
75
76
77
package fastly
import "fmt"
// Settings represents a backend response from the Fastly API.
type Settings struct {
ServiceID string `mapstructure:"service_id"`
Version string `mapstructure:"version"`
DefaultTTL uint `mapstructure:"general.default_ttl"`
DefaultHost string `mapstructure:"general.default_host"`
}
// GetSettingsInput is used as input to the GetSettings function.
type GetSettingsInput struct {
// Service is the ID of the service. Version is the specific configuration
// version. Both fields are required.
Service string
Version string
}
// GetSettings gets the backend configuration with the given parameters.
func (c *Client) GetSettings(i *GetSettingsInput) (*Settings, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == "" {
return nil, ErrMissingVersion
}
path := fmt.Sprintf("/service/%s/version/%s/settings", i.Service, i.Version)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var b *Settings
if err := decodeJSON(&b, resp.Body); err != nil {
return nil, err
}
return b, nil
}
// UpdateSettingsInput is used as input to the UpdateSettings function.
type UpdateSettingsInput struct {
// Service is the ID of the service. Version is the specific configuration
// version. Both fields are required.
Service string
Version string
DefaultTTL uint `form:"general.default_ttl,omitempty"`
DefaultHost string `form:"general.default_host,omitempty"`
}
// UpdateSettings updates a specific backend.
func (c *Client) UpdateSettings(i *UpdateSettingsInput) (*Settings, error) {
if i.Service == "" {
return nil, ErrMissingService
}
if i.Version == "" {
return nil, ErrMissingVersion
}
path := fmt.Sprintf("/service/%s/version/%s/settings", i.Service, i.Version)
resp, err := c.PutForm(path, i, nil)
if err != nil {
return nil, err
}
var b *Settings
if err := decodeJSON(&b, resp.Body); err != nil {
return nil, err
}
return b, nil
}