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/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: "",