forked from rancher/go-rancher
/
generated_question.go
105 lines (79 loc) · 2.89 KB
/
generated_question.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package catalog
const (
QUESTION_TYPE = "question"
)
type Question struct {
Resource
Default string `json:"default,omitempty" yaml:"default,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Group string `json:"group,omitempty" yaml:"group,omitempty"`
InvalidChars string `json:"invalidChars,omitempty" yaml:"invalid_chars,omitempty"`
Label string `json:"label,omitempty" yaml:"label,omitempty"`
Max int64 `json:"max,omitempty" yaml:"max,omitempty"`
MaxLength int64 `json:"maxLength,omitempty" yaml:"max_length,omitempty"`
Min int64 `json:"min,omitempty" yaml:"min,omitempty"`
MinLength int64 `json:"minLength,omitempty" yaml:"min_length,omitempty"`
Options []string `json:"options,omitempty" yaml:"options,omitempty"`
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
Type string `json:"type,omitempty" yaml:"type,omitempty"`
ValidChars string `json:"validChars,omitempty" yaml:"valid_chars,omitempty"`
Variable string `json:"variable,omitempty" yaml:"variable,omitempty"`
}
type QuestionCollection struct {
Collection
Data []Question `json:"data,omitempty"`
client *QuestionClient
}
type QuestionClient struct {
rancherClient *RancherClient
}
type QuestionOperations interface {
List(opts *ListOpts) (*QuestionCollection, error)
Create(opts *Question) (*Question, error)
Update(existing *Question, updates interface{}) (*Question, error)
ById(id string) (*Question, error)
Delete(container *Question) error
}
func newQuestionClient(rancherClient *RancherClient) *QuestionClient {
return &QuestionClient{
rancherClient: rancherClient,
}
}
func (c *QuestionClient) Create(container *Question) (*Question, error) {
resp := &Question{}
err := c.rancherClient.doCreate(QUESTION_TYPE, container, resp)
return resp, err
}
func (c *QuestionClient) Update(existing *Question, updates interface{}) (*Question, error) {
resp := &Question{}
err := c.rancherClient.doUpdate(QUESTION_TYPE, &existing.Resource, updates, resp)
return resp, err
}
func (c *QuestionClient) List(opts *ListOpts) (*QuestionCollection, error) {
resp := &QuestionCollection{}
err := c.rancherClient.doList(QUESTION_TYPE, opts, resp)
resp.client = c
return resp, err
}
func (cc *QuestionCollection) Next() (*QuestionCollection, error) {
if cc != nil && cc.Pagination != nil && cc.Pagination.Next != "" {
resp := &QuestionCollection{}
err := cc.client.rancherClient.doNext(cc.Pagination.Next, resp)
resp.client = cc.client
return resp, err
}
return nil, nil
}
func (c *QuestionClient) ById(id string) (*Question, error) {
resp := &Question{}
err := c.rancherClient.doById(QUESTION_TYPE, id, resp)
if apiError, ok := err.(*ApiError); ok {
if apiError.StatusCode == 404 {
return nil, nil
}
}
return resp, err
}
func (c *QuestionClient) Delete(container *Question) error {
return c.rancherClient.doResourceDelete(QUESTION_TYPE, &container.Resource)
}