change all time fields to have type time.Time (#190)
* add Volume.Unmarshal
* add volumetenants.VolumeExt.Unmarshal
* create servers.Server time.Time fields
* json.Unmarshal can correctly handle time.RFC3339 (Server time fields)
* add v3 Token UnmarshalJSON method
* check for empty string when unmarshaling time
* add Member UnmarshalJSON
* v3 tokens.Token ExtractInto
* v3 trust.Trust UnmarshalJSON
* time.Time fields swift response objects
* time.Time fields for orchestration response objects
* time.Time fields for shared file systems response objects
* if we don't use pointers for the custom time fields, we don't need to check if they're nil
* style guide fixes: 'r' for receiver, 's' for struct
* remove unnecessary pointers from UnmarshalJSON methods
diff --git a/openstack/blockstorage/v2/volumes/results.go b/openstack/blockstorage/v2/volumes/results.go
index 41fbf5c..674ec34 100644
--- a/openstack/blockstorage/v2/volumes/results.go
+++ b/openstack/blockstorage/v2/volumes/results.go
@@ -1,18 +1,38 @@
package volumes
import (
+ "encoding/json"
+ "time"
+
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
type Attachment struct {
- AttachedAt gophercloud.JSONRFC3339MilliNoZ `json:"attached_at"`
- AttachmentID string `json:"attachment_id"`
- Device string `json:"device"`
- HostName string `json:"host_name"`
- ID string `json:"id"`
- ServerID string `json:"server_id"`
- VolumeID string `json:"volume_id"`
+ AttachedAt time.Time `json:"-"`
+ AttachmentID string `json:"attachment_id"`
+ Device string `json:"device"`
+ HostName string `json:"host_name"`
+ ID string `json:"id"`
+ ServerID string `json:"server_id"`
+ VolumeID string `json:"volume_id"`
+}
+
+func (r *Attachment) UnmarshalJSON(b []byte) error {
+ type tmp Attachment
+ var s struct {
+ tmp
+ AttachedAt gophercloud.JSONRFC3339MilliNoZ `json:"attached_at"`
+ }
+ err := json.Unmarshal(b, &s)
+ if err != nil {
+ return err
+ }
+ *r = Attachment(s.tmp)
+
+ r.AttachedAt = time.Time(s.AttachedAt)
+
+ return err
}
// Volume contains all the information associated with an OpenStack Volume.
@@ -26,9 +46,9 @@
// AvailabilityZone is which availability zone the volume is in.
AvailabilityZone string `json:"availability_zone"`
// The date when this volume was created.
- CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"`
+ CreatedAt time.Time `json:"-"`
// The date when this volume was last updated
- UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"`
+ UpdatedAt time.Time `json:"-"`
// Instances onto which the volume is attached.
Attachments []Attachment `json:"attachments"`
// Human-readable display name for the volume.
@@ -57,6 +77,25 @@
Multiattach bool `json:"multiattach"`
}
+func (r *Volume) UnmarshalJSON(b []byte) error {
+ type tmp Volume
+ var s struct {
+ tmp
+ CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"`
+ UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"`
+ }
+ err := json.Unmarshal(b, &s)
+ if err != nil {
+ return err
+ }
+ *r = Volume(s.tmp)
+
+ r.CreatedAt = time.Time(s.CreatedAt)
+ r.UpdatedAt = time.Time(s.UpdatedAt)
+
+ return err
+}
+
// VolumePage is a pagination.pager that is returned from a call to the List function.
type VolumePage struct {
pagination.SinglePageBase