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/sharedfilesystems/v2/securityservices/results.go b/openstack/sharedfilesystems/v2/securityservices/results.go
index 746b2b3..6874208 100644
--- a/openstack/sharedfilesystems/v2/securityservices/results.go
+++ b/openstack/sharedfilesystems/v2/securityservices/results.go
@@ -1,6 +1,11 @@
package securityservices
-import "github.com/gophercloud/gophercloud"
+import (
+ "encoding/json"
+ "time"
+
+ "github.com/gophercloud/gophercloud"
+)
// SecurityService contains all the information associated with an OpenStack
// SecurityService.
@@ -28,9 +33,28 @@
// The security service host name or IP address
Server string `json:"server"`
// The date and time stamp when the security service was created
- CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"`
+ CreatedAt time.Time `json:"-"`
// The date and time stamp when the security service was updated
- UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"`
+ UpdatedAt time.Time `json:"-"`
+}
+
+func (r *SecurityService) UnmarshalJSON(b []byte) error {
+ type tmp SecurityService
+ 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 = SecurityService(s.tmp)
+
+ r.CreatedAt = time.Time(s.CreatedAt)
+ r.UpdatedAt = time.Time(s.UpdatedAt)
+
+ return nil
}
type commonResult struct {
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/results.go b/openstack/sharedfilesystems/v2/sharenetworks/results.go
index 1eb64bc..6762ef2 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/results.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/results.go
@@ -1,8 +1,10 @@
package sharenetworks
import (
+ "encoding/json"
"net/url"
"strconv"
+ "time"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
@@ -34,9 +36,28 @@
// The Share Network description
Description string `json:"description"`
// The date and time stamp when the Share Network was created
- CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"`
+ CreatedAt time.Time `json:"-"`
// The date and time stamp when the Share Network was updated
- UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"`
+ UpdatedAt time.Time `json:"-"`
+}
+
+func (r *ShareNetwork) UnmarshalJSON(b []byte) error {
+ type tmp ShareNetwork
+ 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 = ShareNetwork(s.tmp)
+
+ r.CreatedAt = time.Time(s.CreatedAt)
+ r.UpdatedAt = time.Time(s.UpdatedAt)
+
+ return nil
}
type commonResult struct {
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go b/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go
index 0b28623..46c2d92 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go
@@ -4,7 +4,6 @@
"testing"
"time"
- "github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharenetworks"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
@@ -63,7 +62,7 @@
{
ID: "32763294-e3d4-456a-998d-60047677c2fb",
Name: "net_my1",
- CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 57, 13, 0, time.UTC)),
+ CreatedAt: time.Date(2015, 9, 4, 14, 57, 13, 0, time.UTC),
Description: "descr",
NetworkType: "",
CIDR: "",
@@ -72,13 +71,13 @@
NeutronSubnetID: "53482b62-2c84-4a53-b6ab-30d9d9800d06",
IPVersion: 0,
SegmentationID: 0,
- UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(nilTime),
+ UpdatedAt: nilTime,
ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1",
},
{
ID: "713df749-aac0-4a54-af52-10f6c991e80c",
Name: "net_my",
- CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 54, 25, 0, time.UTC)),
+ CreatedAt: time.Date(2015, 9, 4, 14, 54, 25, 0, time.UTC),
Description: "desecr",
NetworkType: "",
CIDR: "",
@@ -87,13 +86,13 @@
NeutronSubnetID: "53482b62-2c84-4a53-b6ab-30d9d9800d06",
IPVersion: 0,
SegmentationID: 0,
- UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(nilTime),
+ UpdatedAt: nilTime,
ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1",
},
{
ID: "fa158a3d-6d9f-4187-9ca5-abbb82646eb2",
Name: "",
- CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 51, 41, 0, time.UTC)),
+ CreatedAt: time.Date(2015, 9, 4, 14, 51, 41, 0, time.UTC),
Description: "",
NetworkType: "",
CIDR: "",
@@ -102,7 +101,7 @@
NeutronSubnetID: "",
IPVersion: 0,
SegmentationID: 0,
- UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(nilTime),
+ UpdatedAt: nilTime,
ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1",
},
}
@@ -150,7 +149,7 @@
expected := sharenetworks.ShareNetwork{
ID: "7f950b52-6141-4a08-bbb5-bb7ffa3ea5fd",
Name: "net_my1",
- CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 56, 45, 0, time.UTC)),
+ CreatedAt: time.Date(2015, 9, 4, 14, 56, 45, 0, time.UTC),
Description: "descr",
NetworkType: "",
CIDR: "",
@@ -159,7 +158,7 @@
NeutronSubnetID: "53482b62-2c84-4a53-b6ab-30d9d9800d06",
IPVersion: 0,
SegmentationID: 0,
- UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(nilTime),
+ UpdatedAt: nilTime,
ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1",
}
@@ -179,7 +178,7 @@
expected := sharenetworks.ShareNetwork{
ID: "713df749-aac0-4a54-af52-10f6c991e80c",
Name: "net_my2",
- CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 54, 25, 0, time.UTC)),
+ CreatedAt: time.Date(2015, 9, 4, 14, 54, 25, 0, time.UTC),
Description: "new description",
NetworkType: "",
CIDR: "",
@@ -188,7 +187,7 @@
NeutronSubnetID: "new-neutron-subnet-id",
IPVersion: 4,
SegmentationID: 0,
- UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 7, 8, 2, 53, 512184000, time.UTC)),
+ UpdatedAt: time.Date(2015, 9, 7, 8, 2, 53, 512184000, time.UTC),
ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1",
}
@@ -214,7 +213,7 @@
expected := sharenetworks.ShareNetwork{
ID: "713df749-aac0-4a54-af52-10f6c991e80c",
Name: "net_my2",
- CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 54, 25, 0, time.UTC)),
+ CreatedAt: time.Date(2015, 9, 4, 14, 54, 25, 0, time.UTC),
Description: "new description",
NetworkType: "",
CIDR: "",
@@ -223,7 +222,7 @@
NeutronSubnetID: "",
IPVersion: 4,
SegmentationID: 0,
- UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 7, 8, 2, 53, 512184000, time.UTC)),
+ UpdatedAt: time.Date(2015, 9, 7, 8, 2, 53, 512184000, time.UTC),
ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1",
}
diff --git a/openstack/sharedfilesystems/v2/shares/results.go b/openstack/sharedfilesystems/v2/shares/results.go
index aef9f9a..224d1df 100644
--- a/openstack/sharedfilesystems/v2/shares/results.go
+++ b/openstack/sharedfilesystems/v2/shares/results.go
@@ -1,6 +1,9 @@
package shares
import (
+ "encoding/json"
+ "time"
+
"github.com/gophercloud/gophercloud"
)
@@ -60,7 +63,24 @@
SnapshotSupport bool `json:"snapshot_support"`
SourceCgsnapshotMemberID string `json:"source_cgsnapshot_member_id"`
// Timestamp when the share was created
- CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"`
+ CreatedAt time.Time `json:"-"`
+}
+
+func (r *Share) UnmarshalJSON(b []byte) error {
+ type tmp Share
+ var s struct {
+ tmp
+ CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"`
+ }
+ err := json.Unmarshal(b, &s)
+ if err != nil {
+ return err
+ }
+ *r = Share(s.tmp)
+
+ r.CreatedAt = time.Time(s.CreatedAt)
+
+ return nil
}
type commonResult struct {
diff --git a/openstack/sharedfilesystems/v2/shares/testing/request_test.go b/openstack/sharedfilesystems/v2/shares/testing/request_test.go
index 7735e02..5b700a6 100644
--- a/openstack/sharedfilesystems/v2/shares/testing/request_test.go
+++ b/openstack/sharedfilesystems/v2/shares/testing/request_test.go
@@ -1,12 +1,12 @@
package testing
import (
- "github.com/gophercloud/gophercloud"
+ "testing"
+ "time"
+
"github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
- "testing"
- "time"
)
func TestCreate(t *testing.T) {
@@ -57,16 +57,15 @@
"project": "my_app",
"aim": "doc",
},
- Status: "available",
- Description: "My custom share London",
- Host: "manila2@generic1#GENERIC1",
- HasReplicas: false,
- ReplicationType: "",
- TaskState: "",
- SnapshotSupport: true,
- Name: "my_test_share",
- CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(
- 2015, time.September, 18, 10, 25, 24, 0, time.UTC)),
+ Status: "available",
+ Description: "My custom share London",
+ Host: "manila2@generic1#GENERIC1",
+ HasReplicas: false,
+ ReplicationType: "",
+ TaskState: "",
+ SnapshotSupport: true,
+ Name: "my_test_share",
+ CreatedAt: time.Date(2015, time.September, 18, 10, 25, 24, 0, time.UTC),
ShareProto: "NFS",
VolumeType: "default",
SourceCgsnapshotMemberID: "",