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