File: results.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,416 kB
  • sloc: sh: 99; makefile: 21
file content (70 lines) | stat: -rw-r--r-- 1,977 bytes parent folder | download
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
60
61
62
63
64
65
66
67
68
69
70
package events

import (
	"time"

	"github.com/gophercloud/gophercloud"
	"github.com/gophercloud/gophercloud/pagination"
)

// Event represents a detailed Event.
type Event struct {
	Action       string                 `json:"action"`
	Cluster      string                 `json:"cluster"`
	ClusterID    string                 `json:"cluster_id"`
	ID           string                 `json:"id"`
	Level        string                 `json:"level"`
	Metadata     map[string]interface{} `json:"meta_data"`
	OID          string                 `json:"oid"`
	OName        string                 `json:"oname"`
	OType        string                 `json:"otype"`
	Project      string                 `json:"project"`
	Status       string                 `json:"status"`
	StatusReason string                 `json:"status_reason"`
	Timestamp    time.Time              `json:"timestamp"`
	User         string                 `json:"user"`
}

// commonResult is the response of a base result.
type commonResult struct {
	gophercloud.Result
}

// Extract interprets any commonResult-based result as an Event.
func (r commonResult) Extract() (*Event, error) {
	var s struct {
		Event *Event `json:"event"`
	}
	err := r.ExtractInto(&s)
	return s.Event, err
}

// GetResult is the response of a Get operations. Call its Extract method to
// interpret it as an Event.
type GetResult struct {
	commonResult
}

// EventPage contains a single page of all events from a List call.
type EventPage struct {
	pagination.LinkedPageBase
}

// IsEmpty determines if a EventPage contains any results.
func (r EventPage) IsEmpty() (bool, error) {
	if r.StatusCode == 204 {
		return true, nil
	}

	events, err := ExtractEvents(r)
	return len(events) == 0, err
}

// ExtractEvents returns a slice of Events from the List operation.
func ExtractEvents(r pagination.Page) ([]Event, error) {
	var s struct {
		Events []Event `json:"events"`
	}
	err := (r.(EventPage)).ExtractInto(&s)
	return s.Events, err
}