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/stackresources/results.go b/openstack/orchestration/v1/stackresources/results.go
index bd3e29f..59c02a3 100644
--- a/openstack/orchestration/v1/stackresources/results.go
+++ b/openstack/orchestration/v1/stackresources/results.go
@@ -2,6 +2,7 @@
import (
"encoding/json"
+ "time"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
@@ -9,18 +10,37 @@
// Resource represents a stack resource.
type Resource struct {
- Attributes map[string]interface{} `json:"attributes"`
- CreationTime gophercloud.JSONRFC3339NoZ `json:"creation_time"`
- Description string `json:"description"`
- Links []gophercloud.Link `json:"links"`
- LogicalID string `json:"logical_resource_id"`
- Name string `json:"resource_name"`
- PhysicalID string `json:"physical_resource_id"`
- RequiredBy []interface{} `json:"required_by"`
- Status string `json:"resource_status"`
- StatusReason string `json:"resource_status_reason"`
- Type string `json:"resource_type"`
- UpdatedTime gophercloud.JSONRFC3339NoZ `json:"updated_time"`
+ Attributes map[string]interface{} `json:"attributes"`
+ CreationTime time.Time `json:"-"`
+ Description string `json:"description"`
+ Links []gophercloud.Link `json:"links"`
+ LogicalID string `json:"logical_resource_id"`
+ Name string `json:"resource_name"`
+ PhysicalID string `json:"physical_resource_id"`
+ RequiredBy []interface{} `json:"required_by"`
+ Status string `json:"resource_status"`
+ StatusReason string `json:"resource_status_reason"`
+ Type string `json:"resource_type"`
+ UpdatedTime time.Time `json:"-"`
+}
+
+func (r *Resource) UnmarshalJSON(b []byte) error {
+ type tmp Resource
+ 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 = Resource(s.tmp)
+
+ r.CreationTime = time.Time(s.CreationTime)
+ r.UpdatedTime = time.Time(s.UpdatedTime)
+
+ return nil
}
// FindResult represents the result of a Find operation.