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