@@ -21,18 +21,18 @@ type Image struct {
21
21
22
22
Tags []string
23
23
24
- ContainerFormat string `mapstructure:"container_format"`
25
- DiskFormat string `mapstructure:"disk_format"`
24
+ ContainerFormat string
25
+ DiskFormat string
26
26
27
27
MinDiskGigabytes int `mapstructure:"min_disk"`
28
28
MinRamMegabytes int `mapstructure:"min_ram"`
29
29
30
- Owner string `mapstructure:"owner"`
30
+ Owner string
31
31
32
- Protected bool `mapstructure:"protected"`
33
- Visibility ImageVisibility `mapstructure:"visibility"`
32
+ Protected bool
33
+ Visibility ImageVisibility
34
34
35
- Checksum string `mapstructure:"checksum"`
35
+ Checksum * string `mapstructure:"checksum"`
36
36
SizeBytes int `mapstructure:"size"`
37
37
38
38
Metadata map [string ]string `mapstructure:"metadata"`
@@ -65,6 +65,18 @@ func asString(any interface{}) (string, error) {
65
65
}
66
66
}
67
67
68
+ func asNoneableString (any interface {}) (* string , error ) {
69
+ if str , ok := any .(string ); ok {
70
+ if str == "None" {
71
+ return nil , nil
72
+ } else {
73
+ return & str , nil
74
+ }
75
+ } else {
76
+ return nil , errors .New (fmt .Sprintf ("expected string value, but found: %#v" , any ))
77
+ }
78
+ }
79
+
68
80
func extractBoolAtKey (m map [string ]interface {}, k string ) (bool , error ) {
69
81
if any , ok := m [k ]; ok {
70
82
return asBool (any )
@@ -81,6 +93,14 @@ func extractStringAtKey(m map[string]interface{}, k string) (string, error) {
81
93
}
82
94
}
83
95
96
+ func extractNoneableStringAtKey (m map [string ]interface {}, k string ) (* string , error ) {
97
+ if any , ok := m [k ]; ok {
98
+ return asNoneableString (any )
99
+ } else {
100
+ return nil , errors .New (fmt .Sprintf ("expected key \" %s\" in map, but this key is not present" , k ))
101
+ }
102
+ }
103
+
84
104
func extractStringSliceAtKey (m map [string ]interface {}, k string ) ([]string , error ) {
85
105
if any , ok := m [k ]; ok {
86
106
if slice , ok := any .([]interface {}); ok {
@@ -193,6 +213,10 @@ func extractImage(res gophercloud.ErrResult) (*Image, error) {
193
213
if image .Visibility , err = extractImageVisibilityAtKey (body , "visibility" ); err != nil {
194
214
return nil , err
195
215
}
216
+
217
+ if image .Checksum , err = extractNoneableStringAtKey (body , "checksum" ); err != nil {
218
+ return nil , err
219
+ }
196
220
197
221
return & image , nil
198
222
}
0 commit comments