remove mapstructure from blockstorage,cdn,compute,db pkgs
diff --git a/results.go b/results.go
index 8161a89..21c66e3 100644
--- a/results.go
+++ b/results.go
@@ -1,9 +1,12 @@
package gophercloud
import (
+ "bytes"
"encoding/json"
+ "io"
"net/http"
"reflect"
+ "time"
"github.com/mitchellh/mapstructure"
)
@@ -35,6 +38,31 @@
Err error
}
+// ExtractInto allows users to provide an object into which `Extract` will extract
+// the `Result.Body`. This would be useful for OpenStack providers that have
+// different fields in the response object than OpenStack proper.
+func (r Result) ExtractInto(to interface{}) error {
+ if r.Err != nil {
+ return r.Err
+ }
+
+ if reader, ok := r.Body.(io.Reader); ok {
+ if readCloser, ok := reader.(io.Closer); ok {
+ defer readCloser.Close()
+ }
+ jsonDecoder := json.NewDecoder(reader)
+ return jsonDecoder.Decode(to)
+ }
+
+ b, err := json.Marshal(r.Body)
+ if err != nil {
+ return err
+ }
+ err = json.Unmarshal(b, to)
+
+ return err
+}
+
// PrettyPrintJSON creates a string containing the full response body as
// pretty-printed JSON. It's useful for capturing test fixtures and for
// debugging extraction bugs. If you include its output in an issue related to
@@ -113,6 +141,42 @@
// RFC3339Milli describes a common time format used by some API responses.
const RFC3339Milli = "2006-01-02T15:04:05.999999Z"
+const RFC3339MilliNoZ = "2006-01-02T03:04:05.999999"
+
+type JSONRFC3339Milli time.Time
+
+func (jt *JSONRFC3339Milli) UnmarshalJSON(data []byte) error {
+ b := bytes.NewBuffer(data)
+ dec := json.NewDecoder(b)
+ var s string
+ if err := dec.Decode(&s); err != nil {
+ return err
+ }
+ t, err := time.Parse(RFC3339Milli, s)
+ if err != nil {
+ return err
+ }
+ *jt = JSONRFC3339Milli(t)
+ return nil
+}
+
+type JSONRFC3339MilliNoZ time.Time
+
+func (jt *JSONRFC3339MilliNoZ) UnmarshalJSON(data []byte) error {
+ b := bytes.NewBuffer(data)
+ dec := json.NewDecoder(b)
+ var s string
+ if err := dec.Decode(&s); err != nil {
+ return err
+ }
+ t, err := time.Parse(RFC3339MilliNoZ, s)
+ if err != nil {
+ return err
+ }
+ *jt = JSONRFC3339MilliNoZ(t)
+ return nil
+}
+
// StackFmtTime is the time format used in Heat (Orchestration).
const StackFmtTime = "2006-01-02T15:04:05"
@@ -125,8 +189,8 @@
Rel field set to "next".
*/
type Link struct {
- Href string `mapstructure:"href"`
- Rel string `mapstructure:"rel"`
+ Href string `json:"href"`
+ Rel string `json:"rel"`
}
/*