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/imageservice/v2/images/results.go b/openstack/imageservice/v2/images/results.go
index 653c68c..ae674de 100644
--- a/openstack/imageservice/v2/images/results.go
+++ b/openstack/imageservice/v2/images/results.go
@@ -66,10 +66,10 @@
Properties map[string]string `json:"properties"`
// CreatedAt is the date when the image has been created.
- CreatedAt time.Time `json:"-"`
+ CreatedAt time.Time `json:"created_at"`
// UpdatedAt is the date when the last change has been made to the image or it's properties.
- UpdatedAt time.Time `json:"-"`
+ UpdatedAt time.Time `json:"updated_at"`
// File is the trailing path after the glance endpoint that represent the location
// of the image or the path to retrieve it.
@@ -79,36 +79,29 @@
Schema string `json:"schema"`
}
-func (s *Image) UnmarshalJSON(b []byte) error {
+func (r *Image) UnmarshalJSON(b []byte) error {
type tmp Image
- var p *struct {
+ var s struct {
tmp
SizeBytes interface{} `json:"size"`
- CreatedAt string `json:"created_at"`
- UpdatedAt string `json:"updated_at"`
}
- err := json.Unmarshal(b, &p)
+ err := json.Unmarshal(b, &s)
if err != nil {
return err
}
- *s = Image(p.tmp)
+ *r = Image(s.tmp)
- switch t := p.SizeBytes.(type) {
+ switch t := s.SizeBytes.(type) {
case nil:
return nil
case float32:
- s.SizeBytes = int64(t)
+ r.SizeBytes = int64(t)
case float64:
- s.SizeBytes = int64(t)
+ r.SizeBytes = int64(t)
default:
return fmt.Errorf("Unknown type for SizeBytes: %v (value: %v)", reflect.TypeOf(t), t)
}
- s.CreatedAt, err = time.Parse(time.RFC3339, p.CreatedAt)
- if err != nil {
- return err
- }
- s.UpdatedAt, err = time.Parse(time.RFC3339, p.UpdatedAt)
return err
}