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/orchestration/v1/stacks/results.go b/openstack/orchestration/v1/stacks/results.go
index 6b6f3a3..8df5419 100644
--- a/openstack/orchestration/v1/stacks/results.go
+++ b/openstack/orchestration/v1/stacks/results.go
@@ -2,6 +2,7 @@
import (
"encoding/json"
+ "time"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
@@ -47,15 +48,34 @@
// ListedStack represents an element in the slice extracted from a List operation.
type ListedStack struct {
- CreationTime gophercloud.JSONRFC3339NoZ `json:"creation_time"`
- Description string `json:"description"`
- ID string `json:"id"`
- Links []gophercloud.Link `json:"links"`
- Name string `json:"stack_name"`
- Status string `json:"stack_status"`
- StatusReason string `json:"stack_status_reason"`
- Tags []string `json:"tags"`
- UpdatedTime gophercloud.JSONRFC3339NoZ `json:"updated_time"`
+ CreationTime time.Time `json:"-"`
+ Description string `json:"description"`
+ ID string `json:"id"`
+ Links []gophercloud.Link `json:"links"`
+ Name string `json:"stack_name"`
+ Status string `json:"stack_status"`
+ StatusReason string `json:"stack_status_reason"`
+ Tags []string `json:"tags"`
+ UpdatedTime time.Time `json:"-"`
+}
+
+func (r *ListedStack) UnmarshalJSON(b []byte) error {
+ type tmp ListedStack
+ var s struct {
+ tmp
+ CreationTime gophercloud.JSONRFC3339NoZ `json:"creation_time"`
+ UpdatedTime gophercloud.JSONRFC3339NoZ `json:"updated_time"`
+ }
+ err := json.Unmarshal(b, &s)
+ if err != nil {
+ return err
+ }
+ *r = ListedStack(s.tmp)
+
+ r.CreationTime = time.Time(s.CreationTime)
+ r.UpdatedTime = time.Time(s.UpdatedTime)
+
+ return nil
}
// ExtractStacks extracts and returns a slice of ListedStack. It is used while iterating
@@ -70,22 +90,41 @@
// RetrievedStack represents the object extracted from a Get operation.
type RetrievedStack struct {
- Capabilities []interface{} `json:"capabilities"`
- CreationTime gophercloud.JSONRFC3339NoZ `json:"creation_time"`
- Description string `json:"description"`
- DisableRollback bool `json:"disable_rollback"`
- ID string `json:"id"`
- Links []gophercloud.Link `json:"links"`
- NotificationTopics []interface{} `json:"notification_topics"`
- Outputs []map[string]interface{} `json:"outputs"`
- Parameters map[string]string `json:"parameters"`
- Name string `json:"stack_name"`
- Status string `json:"stack_status"`
- StatusReason string `json:"stack_status_reason"`
- Tags []string `json:"tags"`
- TemplateDescription string `json:"template_description"`
- Timeout int `json:"timeout_mins"`
- UpdatedTime gophercloud.JSONRFC3339NoZ `json:"updated_time"`
+ Capabilities []interface{} `json:"capabilities"`
+ CreationTime time.Time `json:"-"`
+ Description string `json:"description"`
+ DisableRollback bool `json:"disable_rollback"`
+ ID string `json:"id"`
+ Links []gophercloud.Link `json:"links"`
+ NotificationTopics []interface{} `json:"notification_topics"`
+ Outputs []map[string]interface{} `json:"outputs"`
+ Parameters map[string]string `json:"parameters"`
+ Name string `json:"stack_name"`
+ Status string `json:"stack_status"`
+ StatusReason string `json:"stack_status_reason"`
+ Tags []string `json:"tags"`
+ TemplateDescription string `json:"template_description"`
+ Timeout int `json:"timeout_mins"`
+ UpdatedTime time.Time `json:"-"`
+}
+
+func (r *RetrievedStack) UnmarshalJSON(b []byte) error {
+ type tmp RetrievedStack
+ var s struct {
+ tmp
+ CreationTime gophercloud.JSONRFC3339NoZ `json:"creation_time"`
+ UpdatedTime gophercloud.JSONRFC3339NoZ `json:"updated_time"`
+ }
+ err := json.Unmarshal(b, &s)
+ if err != nil {
+ return err
+ }
+ *r = RetrievedStack(s.tmp)
+
+ r.CreationTime = time.Time(s.CreationTime)
+ r.UpdatedTime = time.Time(s.UpdatedTime)
+
+ return nil
}
// GetResult represents the result of a Get operation.
@@ -115,19 +154,38 @@
// PreviewedStack represents the result of a Preview operation.
type PreviewedStack struct {
- Capabilities []interface{} `json:"capabilities"`
- CreationTime gophercloud.JSONRFC3339NoZ `json:"creation_time"`
- Description string `json:"description"`
- DisableRollback bool `json:"disable_rollback"`
- ID string `json:"id"`
- Links []gophercloud.Link `json:"links"`
- Name string `json:"stack_name"`
- NotificationTopics []interface{} `json:"notification_topics"`
- Parameters map[string]string `json:"parameters"`
- Resources []interface{} `json:"resources"`
- TemplateDescription string `json:"template_description"`
- Timeout int `json:"timeout_mins"`
- UpdatedTime gophercloud.JSONRFC3339NoZ `json:"updated_time"`
+ Capabilities []interface{} `json:"capabilities"`
+ CreationTime time.Time `json:"-"`
+ Description string `json:"description"`
+ DisableRollback bool `json:"disable_rollback"`
+ ID string `json:"id"`
+ Links []gophercloud.Link `json:"links"`
+ Name string `json:"stack_name"`
+ NotificationTopics []interface{} `json:"notification_topics"`
+ Parameters map[string]string `json:"parameters"`
+ Resources []interface{} `json:"resources"`
+ TemplateDescription string `json:"template_description"`
+ Timeout int `json:"timeout_mins"`
+ UpdatedTime time.Time `json:"-"`
+}
+
+func (r *PreviewedStack) UnmarshalJSON(b []byte) error {
+ type tmp PreviewedStack
+ var s struct {
+ tmp
+ CreationTime gophercloud.JSONRFC3339NoZ `json:"creation_time"`
+ UpdatedTime gophercloud.JSONRFC3339NoZ `json:"updated_time"`
+ }
+ err := json.Unmarshal(b, &s)
+ if err != nil {
+ return err
+ }
+ *r = PreviewedStack(s.tmp)
+
+ r.CreationTime = time.Time(s.CreationTime)
+ r.UpdatedTime = time.Time(s.UpdatedTime)
+
+ return nil
}
// PreviewResult represents the result of a Preview operation.