Skip to content

Commit fea9073

Browse files
author
Jon Perritt
committed
objectstorage v1 and orchestration v1 struct tags
1 parent e1c6ceb commit fea9073

13 files changed

Lines changed: 359 additions & 704 deletions

File tree

openstack/objectstorage/v1/accounts/requests.go

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,27 @@ func (opts GetOpts) ToAccountGetMap() (map[string]string, error) {
2424
// all the headers that are returned (including the metadata), call the
2525
// ExtractHeader method on the GetResult.
2626
func Get(c *gophercloud.ServiceClient, opts GetOptsBuilder) GetResult {
27-
var res GetResult
28-
h := c.AuthenticatedHeaders()
29-
27+
var r GetResult
28+
h := make(map[string]string)
3029
if opts != nil {
3130
headers, err := opts.ToAccountGetMap()
3231
if err != nil {
33-
res.Err = err
34-
return res
32+
r.Err = err
33+
return r
3534
}
36-
3735
for k, v := range headers {
3836
h[k] = v
3937
}
4038
}
41-
4239
resp, err := c.Request("HEAD", getURL(c), &gophercloud.RequestOpts{
4340
MoreHeaders: h,
4441
OkCodes: []int{204},
4542
})
4643
if resp != nil {
47-
res.Header = resp.Header
44+
r.Header = resp.Header
4845
}
49-
res.Err = err
50-
return res
46+
r.Err = err
47+
return r
5148
}
5249

5350
// UpdateOptsBuilder allows extensions to add additional headers to the Update
@@ -81,27 +78,25 @@ func (opts UpdateOpts) ToAccountUpdateMap() (map[string]string, error) {
8178
// Update is a function that creates, updates, or deletes an account's metadata.
8279
// To extract the headers returned, call the Extract method on the UpdateResult.
8380
func Update(c *gophercloud.ServiceClient, opts UpdateOptsBuilder) UpdateResult {
84-
var res UpdateResult
81+
var r UpdateResult
8582
h := make(map[string]string)
86-
8783
if opts != nil {
8884
headers, err := opts.ToAccountUpdateMap()
8985
if err != nil {
90-
res.Err = err
91-
return res
86+
r.Err = err
87+
return r
9288
}
9389
for k, v := range headers {
9490
h[k] = v
9591
}
9692
}
97-
9893
resp, err := c.Request("POST", updateURL(c), &gophercloud.RequestOpts{
9994
MoreHeaders: h,
10095
OkCodes: []int{201, 202, 204},
10196
})
10297
if resp != nil {
103-
res.Header = resp.Header
98+
r.Header = resp.Header
10499
}
105-
res.Err = err
106-
return res
100+
r.Err = err
101+
return r
107102
}

openstack/objectstorage/v1/containers/requests.go

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ type ListOpts struct {
2626
// representing whether to list complete information for each container.
2727
func (opts ListOpts) ToContainerListParams() (bool, string, error) {
2828
q, err := gophercloud.BuildQueryString(opts)
29-
if err != nil {
30-
return false, "", err
31-
}
32-
return opts.Full, q.String(), nil
29+
return opts.Full, q.String(), err
3330
}
3431

3532
// List is a function that retrieves containers associated with the account as
@@ -51,13 +48,11 @@ func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
5148
}
5249
}
5350

54-
createPage := func(r pagination.PageResult) pagination.Page {
51+
pager := pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
5552
p := ContainerPage{pagination.MarkerPageBase{PageResult: r}}
5653
p.MarkerPageBase.Owner = p
5754
return p
58-
}
59-
60-
pager := pagination.NewPager(c, url, createPage)
55+
})
6156
pager.Headers = headers
6257
return pager
6358
}
@@ -95,37 +90,34 @@ func (opts CreateOpts) ToContainerCreateMap() (map[string]string, error) {
9590

9691
// Create is a function that creates a new container.
9792
func Create(c *gophercloud.ServiceClient, containerName string, opts CreateOptsBuilder) CreateResult {
98-
var res CreateResult
99-
h := c.AuthenticatedHeaders()
100-
93+
var r CreateResult
94+
h := make(map[string]string)
10195
if opts != nil {
10296
headers, err := opts.ToContainerCreateMap()
10397
if err != nil {
104-
res.Err = err
105-
return res
98+
r.Err = err
99+
return r
106100
}
107-
108101
for k, v := range headers {
109102
h[k] = v
110103
}
111104
}
112-
113105
resp, err := c.Request("PUT", createURL(c, containerName), &gophercloud.RequestOpts{
114106
MoreHeaders: h,
115107
OkCodes: []int{201, 202, 204},
116108
})
117109
if resp != nil {
118-
res.Header = resp.Header
110+
r.Header = resp.Header
119111
}
120-
res.Err = err
121-
return res
112+
r.Err = err
113+
return r
122114
}
123115

124116
// Delete is a function that deletes a container.
125117
func Delete(c *gophercloud.ServiceClient, containerName string) DeleteResult {
126-
var res DeleteResult
127-
_, res.Err = c.Delete(deleteURL(c, containerName), nil)
128-
return res
118+
var r DeleteResult
119+
_, r.Err = c.Delete(deleteURL(c, containerName), nil)
120+
return r
129121
}
130122

131123
// UpdateOptsBuilder allows extensions to add additional parameters to the
@@ -163,43 +155,41 @@ func (opts UpdateOpts) ToContainerUpdateMap() (map[string]string, error) {
163155
// Update is a function that creates, updates, or deletes a container's
164156
// metadata.
165157
func Update(c *gophercloud.ServiceClient, containerName string, opts UpdateOptsBuilder) UpdateResult {
166-
var res UpdateResult
167-
h := c.AuthenticatedHeaders()
168-
158+
var r UpdateResult
159+
h := make(map[string]string)
169160
if opts != nil {
170161
headers, err := opts.ToContainerUpdateMap()
171162
if err != nil {
172-
res.Err = err
173-
return res
163+
r.Err = err
164+
return r
174165
}
175166

176167
for k, v := range headers {
177168
h[k] = v
178169
}
179170
}
180-
181171
resp, err := c.Request("POST", updateURL(c, containerName), &gophercloud.RequestOpts{
182172
MoreHeaders: h,
183173
OkCodes: []int{201, 202, 204},
184174
})
185175
if resp != nil {
186-
res.Header = resp.Header
176+
r.Header = resp.Header
187177
}
188-
res.Err = err
189-
return res
178+
r.Err = err
179+
return r
190180
}
191181

192182
// Get is a function that retrieves the metadata of a container. To extract just
193183
// the custom metadata, pass the GetResult response to the ExtractMetadata
194184
// function.
195185
func Get(c *gophercloud.ServiceClient, containerName string) GetResult {
196-
var res GetResult
186+
var r GetResult
197187
resp, err := c.Request("HEAD", getURL(c, containerName), &gophercloud.RequestOpts{
198188
OkCodes: []int{200, 204},
199189
})
200190
if resp != nil {
201-
res.Header = resp.Header
191+
r.Header = resp.Header
202192
}
203-
res.Err = err
204-
return res
193+
r.Err = err
194+
return r
205195
}

0 commit comments

Comments
 (0)