github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/rts/v1/stackevents/results.go (about) 1 package stackevents 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/huaweicloud/golangsdk" 8 "github.com/huaweicloud/golangsdk/pagination" 9 ) 10 11 // Event represents a stack event. 12 type Event struct { 13 // The name of the resource for which the event occurred. 14 ResourceName string `json:"resource_name"` 15 // The time the event occurred. 16 Time time.Time `json:"-"` 17 // The URLs to the event. 18 Links []golangsdk.Link `json:"links"` 19 // The logical ID of the stack resource. 20 LogicalResourceID string `json:"logical_resource_id"` 21 // The reason of the status of the event. 22 ResourceStatusReason string `json:"resource_status_reason"` 23 // The status of the event. 24 ResourceStatus string `json:"resource_status"` 25 // The physical ID of the stack resource. 26 PhysicalResourceID string `json:"physical_resource_id"` 27 // The event ID. 28 ID string `json:"id"` 29 // Properties of the stack resource. 30 ResourceProperties map[string]interface{} `json:"resource_properties"` 31 } 32 33 func (r *Event) UnmarshalJSON(b []byte) error { 34 type tmp Event 35 var s struct { 36 tmp 37 Time golangsdk.JSONRFC3339NoZ `json:"event_time"` 38 } 39 err := json.Unmarshal(b, &s) 40 if err != nil { 41 return err 42 } 43 44 *r = Event(s.tmp) 45 46 r.Time = time.Time(s.Time) 47 48 return nil 49 } 50 51 // FindResult represents the result of a Find operation. 52 type FindResult struct { 53 golangsdk.Result 54 } 55 56 // Extract returns a slice of Event objects and is called after a 57 // Find operation. 58 func (r FindResult) Extract() ([]Event, error) { 59 var s struct { 60 Events []Event `json:"events"` 61 } 62 err := r.ExtractInto(&s) 63 return s.Events, err 64 } 65 66 // EventPage abstracts the raw results of making a List() request against the API. 67 // As OpenStack extensions may freely alter the response bodies of structures returned to the client, you may only safely access the 68 // data provided through the ExtractResources call. 69 type EventPage struct { 70 pagination.MarkerPageBase 71 } 72 73 // IsEmpty returns true if a page contains no Server results. 74 func (r EventPage) IsEmpty() (bool, error) { 75 events, err := ExtractEvents(r) 76 return len(events) == 0, err 77 } 78 79 // LastMarker returns the last stack ID in a ListResult. 80 func (r EventPage) LastMarker() (string, error) { 81 events, err := ExtractEvents(r) 82 if err != nil { 83 return "", err 84 } 85 if len(events) == 0 { 86 return "", nil 87 } 88 return events[len(events)-1].ID, nil 89 } 90 91 // ExtractEvents interprets the results of a single page from a List() call, producing a slice of Event entities. 92 func ExtractEvents(r pagination.Page) ([]Event, error) { 93 var s struct { 94 Events []Event `json:"events"` 95 } 96 err := (r.(EventPage)).ExtractInto(&s) 97 return s.Events, err 98 }