Extract method for Containers
diff --git a/openstack/objectstorage/v1/accounts/results.go b/openstack/objectstorage/v1/accounts/results.go
index 4797e96..63bb134 100644
--- a/openstack/objectstorage/v1/accounts/results.go
+++ b/openstack/objectstorage/v1/accounts/results.go
@@ -2,7 +2,6 @@
import (
"encoding/json"
- "fmt"
"strings"
"time"
@@ -54,7 +53,7 @@
// GetHeader represents the headers returned in the response from a Get request.
type GetHeader struct {
BytesUsed int64 `json:"X-Account-Bytes-Used"`
- ContainerCount int `json:"X-Accound-Container-Count"`
+ ContainerCount int `json:"X-Account-Container-Count"`
ContentLength int64 `json:"Content-Length"`
ContentType string `json:"Content-Type"`
Date time.Time `mapstructure:"-" json:"-"`
@@ -70,19 +69,19 @@
// Extract will return a struct of headers returned from a call to Get. To obtain
// a map of headers, call the ExtractHeader method on the GetResult.
func (gr GetResult) Extract() (GetHeader, error) {
- fmt.Printf("raw response header: %+v\n", gr.Header)
-
var gh GetHeader
if err := mapstructure.Decode(gr.Header, &gh); err != nil {
return gh, err
}
- t, err := time.Parse(time.RFC1123, gr.Header["Date"][0])
- if err != nil {
- return gh, err
+ if date, ok := gr.Header["Date"]; ok && len(date) > 0 {
+ t, err := time.Parse(time.RFC1123, gr.Header["Date"][0])
+ if err != nil {
+ return gh, err
+ }
+ gh.Date = t
}
- gh.Date = t
return gh, nil
}
diff --git a/openstack/objectstorage/v1/containers/results.go b/openstack/objectstorage/v1/containers/results.go
index 74f3286..c2c25a8 100644
--- a/openstack/objectstorage/v1/containers/results.go
+++ b/openstack/objectstorage/v1/containers/results.go
@@ -3,6 +3,7 @@
import (
"fmt"
"strings"
+ "time"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
@@ -96,11 +97,41 @@
}
}
+// GetHeader represents the headers returned in the response from a Get request.
+type GetHeader struct {
+ BytesUsed int64 `json:"X-Account-Bytes-Used"`
+ ContentLength int64 `json:"Content-Length"`
+ ContentType string `json:"Content-Type"`
+ Date time.Time `mapstructure:"-" json:"-"`
+ ObjectCount int64 `json:"X-Account-Object-Count"`
+ TransID string `json:"X-Trans-Id"`
+}
+
// GetResult represents the result of a get operation.
type GetResult struct {
gophercloud.HeaderResult
}
+// Extract will return a struct of headers returned from a call to Get. To obtain
+// a map of headers, call the ExtractHeader method on the GetResult.
+func (gr GetResult) Extract() (GetHeader, error) {
+ var gh GetHeader
+
+ if err := mapstructure.Decode(gr.Header, &gh); err != nil {
+ return gh, err
+ }
+
+ if date, ok := gr.Header["Date"]; ok && len(date) > 0 {
+ t, err := time.Parse(time.RFC1123, gr.Header["Date"][0])
+ if err != nil {
+ return gh, err
+ }
+ gh.Date = t
+ }
+
+ return gh, nil
+}
+
// ExtractMetadata is a function that takes a GetResult (of type *http.Response)
// and returns the custom metadata associated with the container.
func (gr GetResult) ExtractMetadata() (map[string]string, error) {
@@ -117,6 +148,14 @@
return metadata, nil
}
+// CreateHeader represents the headers returned in the response from a Create request.
+type CreateHeader struct {
+ ContentLength int64 `json:"Content-Length"`
+ ContentType string `json:"Content-Type"`
+ Date time.Time `mapstructure:"-" json:"-"`
+ TransID string `json:"X-Trans-Id"`
+}
+
// CreateResult represents the result of a create operation. To extract the
// the headers from the HTTP response, you can invoke the 'ExtractHeader'
// method on the result struct.
@@ -124,6 +163,34 @@
gophercloud.HeaderResult
}
+// Extract will return a struct of headers returned from a call to Create. To obtain
+// a map of headers, call the ExtractHeader method on the CreateResult.
+func (cr CreateResult) Extract() (CreateHeader, error) {
+ var ch CreateHeader
+
+ if err := mapstructure.Decode(cr.Header, &ch); err != nil {
+ return ch, err
+ }
+
+ if date, ok := cr.Header["Date"]; ok && len(date) > 0 {
+ t, err := time.Parse(time.RFC1123, cr.Header["Date"][0])
+ if err != nil {
+ return ch, err
+ }
+ ch.Date = t
+ }
+
+ return ch, nil
+}
+
+// UpdateHeader represents the headers returned in the response from a Update request.
+type UpdateHeader struct {
+ ContentLength int64 `json:"Content-Length"`
+ ContentType string `json:"Content-Type"`
+ Date time.Time `mapstructure:"-" json:"-"`
+ TransID string `json:"X-Trans-Id"`
+}
+
// UpdateResult represents the result of an update operation. To extract the
// the headers from the HTTP response, you can invoke the 'ExtractHeader'
// method on the result struct.
@@ -131,9 +198,57 @@
gophercloud.HeaderResult
}
+// Extract will return a struct of headers returned from a call to Update. To obtain
+// a map of headers, call the ExtractHeader method on the UpdateResult.
+func (ur UpdateResult) Extract() (UpdateHeader, error) {
+ var uh UpdateHeader
+
+ if err := mapstructure.Decode(ur.Header, &uh); err != nil {
+ return uh, err
+ }
+
+ if date, ok := ur.Header["Date"]; ok && len(date) > 0 {
+ t, err := time.Parse(time.RFC1123, ur.Header["Date"][0])
+ if err != nil {
+ return uh, err
+ }
+ uh.Date = t
+ }
+
+ return uh, nil
+}
+
+// DeleteHeader represents the headers returned in the response from a Delete request.
+type DeleteHeader struct {
+ ContentLength int64 `json:"Content-Length"`
+ ContentType string `json:"Content-Type"`
+ Date time.Time `mapstructure:"-" json:"-"`
+ TransID string `json:"X-Trans-Id"`
+}
+
// DeleteResult represents the result of a delete operation. To extract the
// the headers from the HTTP response, you can invoke the 'ExtractHeader'
// method on the result struct.
type DeleteResult struct {
gophercloud.HeaderResult
}
+
+// Extract will return a struct of headers returned from a call to Delete. To obtain
+// a map of headers, call the ExtractHeader method on the DeleteResult.
+func (dr DeleteResult) Extract() (DeleteHeader, error) {
+ var dh DeleteHeader
+
+ if err := mapstructure.Decode(dr.Header, &dh); err != nil {
+ return dh, err
+ }
+
+ if date, ok := dr.Header["Date"]; ok && len(date) > 0 {
+ t, err := time.Parse(time.RFC1123, dr.Header["Date"][0])
+ if err != nil {
+ return dh, err
+ }
+ dh.Date = t
+ }
+
+ return dh, nil
+}