@@ -3,7 +3,6 @@ package v2
3
3
import (
4
4
"errors"
5
5
"fmt"
6
- "reflect"
7
6
8
7
"github.com/rackspace/gophercloud"
9
8
//"github.com/rackspace/gophercloud/pagination"
@@ -101,7 +100,15 @@ func asNoneableInteger(any interface{}) (*int, error) {
101
100
return nil , errors .New (fmt .Sprintf ("expected \" None\" or integer value, but found unexpected string: \" %s\" " , s ))
102
101
}
103
102
} else {
104
- return nil , errors .New (fmt .Sprintf ("expected \" None\" or integer value, but found: %#v of type %s" , any , reflect .TypeOf (any )))
103
+ return nil , errors .New (fmt .Sprintf ("expected \" None\" or integer value, but found: %T(%#v)" , any , any ))
104
+ }
105
+ }
106
+
107
+ func asMapStringString (any interface {}) (map [string ]string , error ) {
108
+ if mss , ok := any .(map [string ]string ); ok {
109
+ return mss , nil
110
+ } else {
111
+ return nil , errors .New (fmt .Sprintf ("expected map[string]string, but found: %#v" , any ))
105
112
}
106
113
}
107
114
@@ -208,6 +215,14 @@ func extractImageVisibilityAtKey(m map[string]interface{}, k string) (ImageVisib
208
215
}
209
216
}
210
217
218
+ func extractMapStringStringAtKeyOptional (m map [string ]interface {}, k string , ifMissing map [string ]string ) (map [string ]string , error ) {
219
+ if any , ok := m [k ]; ok {
220
+ return asMapStringString (any )
221
+ } else {
222
+ return ifMissing , nil
223
+ }
224
+ }
225
+
211
226
func extractImage (res gophercloud.ErrResult ) (* Image , error ) {
212
227
if res .Err != nil {
213
228
return nil , res .Err
@@ -274,6 +289,10 @@ func extractImage(res gophercloud.ErrResult) (*Image, error) {
274
289
return nil , err
275
290
}
276
291
292
+ if image .Metadata , err = extractMapStringStringAtKeyOptional (body , "metadata" , make (map [string ]string )); err != nil {
293
+ return nil , err
294
+ }
295
+
277
296
// TODO Metadata map[string]string `mapstructure:"metadata"`
278
297
// TODO Properties map[string]string `mapstructure:"properties"`
279
298
0 commit comments