Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 661cfb0

Browse files
author
Samuel Ortiz
committed
imageservice: Factorize Get, Update and Create Extract method
They all use the same Extract() implementation, so we can implement it for a commonResult structure and define all 3 structures as commonResult. Signed-off-by: Samuel Ortiz <[email protected]>
1 parent 53050ee commit 661cfb0

File tree

1 file changed

+14
-32
lines changed

1 file changed

+14
-32
lines changed

openstack/imageservice/v2/images/results.go

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,12 @@ type Image struct {
6666
Properties map[string]string
6767
}
6868

69-
// CreateResult model
70-
type CreateResult struct {
69+
type commonResult struct {
7170
gophercloud.Result
7271
}
7372

74-
// Extract build CreateResults from imput Image
75-
func (c CreateResult) Extract() (*Image, error) {
73+
// Extract interprets any commonResult as an Image.
74+
func (c commonResult) Extract() (*Image, error) {
7675
if c.Err != nil {
7776
return nil, c.Err
7877
}
@@ -82,43 +81,26 @@ func (c CreateResult) Extract() (*Image, error) {
8281
return image, err
8382
}
8483

85-
//DeleteResult model
86-
type DeleteResult struct {
87-
gophercloud.Result
84+
// CreateResult represents the result of a Create operation
85+
type CreateResult struct {
86+
commonResult
8887
}
8988

90-
// GetResult model
91-
type GetResult struct {
92-
gophercloud.Result
89+
// UpdateResult represents the result of an Update operation
90+
type UpdateResult struct {
91+
commonResult
9392
}
9493

95-
// Extract builds GetResult
96-
func (c GetResult) Extract() (*Image, error) {
97-
if c.Err != nil {
98-
return nil, c.Err
99-
}
100-
var image *Image
101-
102-
err := mapstructure.Decode(c.Result.Body, &image)
103-
return image, err
94+
// GetResult represents the result of a Get operation
95+
type GetResult struct {
96+
commonResult
10497
}
10598

106-
// UpdateResult model
107-
type UpdateResult struct {
99+
//DeleteResult model
100+
type DeleteResult struct {
108101
gophercloud.Result
109102
}
110103

111-
// Extract builds UpdateResult
112-
func (u UpdateResult) Extract() (*Image, error) {
113-
if u.Err != nil {
114-
return nil, u.Err
115-
}
116-
var image *Image
117-
118-
err := mapstructure.Decode(u.Result.Body, &image)
119-
return image, err
120-
}
121-
122104
// PutImageDataResult is model put image respose
123105
type PutImageDataResult struct {
124106
gophercloud.Result

0 commit comments

Comments
 (0)