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/identity/v3/tokens/results.go b/openstack/identity/v3/tokens/results.go
index 2144a2b..0f1e8c2 100644
--- a/openstack/identity/v3/tokens/results.go
+++ b/openstack/identity/v3/tokens/results.go
@@ -1,7 +1,10 @@
package tokens
-import "errors"
-import "github.com/gophercloud/gophercloud"
+import (
+ "time"
+
+ "github.com/gophercloud/gophercloud"
+)
// Endpoint represents a single API endpoint offered by a service.
// It matches either a public, internal or admin URL.
@@ -35,7 +38,7 @@
// ServiceCatalog provides a view into the service catalog from a previous, successful authentication.
type ServiceCatalog struct {
- Entries []CatalogEntry
+ Entries []CatalogEntry `json:"catalog"`
}
// commonResult is the deferred result of a Create or a Get call.
@@ -51,34 +54,23 @@
// ExtractToken interprets a commonResult as a Token.
func (r commonResult) ExtractToken() (*Token, error) {
- var s struct {
- Token *Token `json:"token"`
- }
-
+ var s Token
err := r.ExtractInto(&s)
if err != nil {
return nil, err
}
- if s.Token == nil {
- return nil, errors.New("'token' missing in JSON response")
- }
-
// Parse the token itself from the stored headers.
- s.Token.ID = r.Header.Get("X-Subject-Token")
+ s.ID = r.Header.Get("X-Subject-Token")
- return s.Token, err
+ return &s, err
}
// ExtractServiceCatalog returns the ServiceCatalog that was generated along with the user's Token.
func (r CreateResult) ExtractServiceCatalog() (*ServiceCatalog, error) {
- var s struct {
- Token struct {
- Entries []CatalogEntry `json:"catalog"`
- } `json:"token"`
- }
+ var s ServiceCatalog
err := r.ExtractInto(&s)
- return &ServiceCatalog{Entries: s.Token.Entries}, err
+ return &s, err
}
// CreateResult defers the interpretation of a created token.
@@ -103,5 +95,9 @@
// ID is the issued token.
ID string `json:"id"`
// ExpiresAt is the timestamp at which this token will no longer be accepted.
- ExpiresAt gophercloud.JSONRFC3339Milli `json:"expires_at"`
+ ExpiresAt time.Time `json:"expires_at"`
+}
+
+func (r commonResult) ExtractInto(v interface{}) error {
+ return r.ExtractIntoStructPtr(v, "token")
}