forked from rancher/convoy
/
generated_setting.go
69 lines (56 loc) · 1.68 KB
/
generated_setting.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
package client
const (
SETTING_TYPE = "setting"
)
type Setting struct {
Resource
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Value string `json:"value,omitempty" yaml:"value,omitempty"`
}
type SettingCollection struct {
Collection
Data []Setting `json:"data,omitempty"`
}
type SettingClient struct {
rancherClient *RancherClient
}
type SettingOperations interface {
List(opts *ListOpts) (*SettingCollection, error)
Create(opts *Setting) (*Setting, error)
Update(existing *Setting, updates interface{}) (*Setting, error)
ById(id string) (*Setting, error)
Delete(container *Setting) error
}
func newSettingClient(rancherClient *RancherClient) *SettingClient {
return &SettingClient{
rancherClient: rancherClient,
}
}
func (c *SettingClient) Create(container *Setting) (*Setting, error) {
resp := &Setting{}
err := c.rancherClient.doCreate(SETTING_TYPE, container, resp)
return resp, err
}
func (c *SettingClient) Update(existing *Setting, updates interface{}) (*Setting, error) {
resp := &Setting{}
err := c.rancherClient.doUpdate(SETTING_TYPE, &existing.Resource, updates, resp)
return resp, err
}
func (c *SettingClient) List(opts *ListOpts) (*SettingCollection, error) {
resp := &SettingCollection{}
err := c.rancherClient.doList(SETTING_TYPE, opts, resp)
return resp, err
}
func (c *SettingClient) ById(id string) (*Setting, error) {
resp := &Setting{}
err := c.rancherClient.doById(SETTING_TYPE, id, resp)
if apiError, ok := err.(*ApiError); ok {
if apiError.StatusCode == 404 {
return nil, nil
}
}
return resp, err
}
func (c *SettingClient) Delete(container *Setting) error {
return c.rancherClient.doResourceDelete(SETTING_TYPE, &container.Resource)
}