1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
package availabilityzones
import (
"encoding/json"
"time"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// AvailabilityZone contains all the information associated with an OpenStack
// AvailabilityZone.
type AvailabilityZone struct {
// The availability zone ID.
ID string `json:"id"`
// The name of the availability zone.
Name string `json:"name"`
// The date and time stamp when the availability zone was created.
CreatedAt time.Time `json:"-"`
// The date and time stamp when the availability zone was updated.
UpdatedAt time.Time `json:"-"`
}
type commonResult struct {
gophercloud.Result
}
// ListResult contains the response body and error from a List request.
type AvailabilityZonePage struct {
pagination.SinglePageBase
}
// ExtractAvailabilityZones will get the AvailabilityZone objects out of the shareTypeAccessResult object.
func ExtractAvailabilityZones(r pagination.Page) ([]AvailabilityZone, error) {
var a struct {
AvailabilityZone []AvailabilityZone `json:"availability_zones"`
}
err := (r.(AvailabilityZonePage)).ExtractInto(&a)
return a.AvailabilityZone, err
}
func (r *AvailabilityZone) UnmarshalJSON(b []byte) error {
type tmp AvailabilityZone
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 = AvailabilityZone(s.tmp)
r.CreatedAt = time.Time(s.CreatedAt)
r.UpdatedAt = time.Time(s.UpdatedAt)
return nil
}
|