forked from gophercloud/gophercloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
requests.go
72 lines (64 loc) · 2.29 KB
/
requests.go
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
71
72
package messages
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// Delete will delete the existing Message with the provided ID.
func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
_, r.Err = client.Delete(deleteURL(client, id), nil)
return
}
// ListOptsBuilder allows extensions to add additional parameters to the List
// request.
type ListOptsBuilder interface {
ToMessageListQuery() (string, error)
}
// ListOpts holds options for listing Messages. It is passed to the
// messages.List function.
type ListOpts struct {
// The message ID
ID string `q:"id"`
// The ID of the action during which the message was created
ActionID string `q:"action_id"`
// The ID of the message detail
DetailID string `q:"detail_id"`
// The message level
MessageLevel string `q:"message_level"`
// The UUID of the request during which the message was created
RequestID string `q:"request_id"`
// The UUID of the resource for which the message was created
ResourceID string `q:"resource_id"`
// The type of the resource for which the message was created
ResourceType string `q:"resource_type"`
// The key to sort a list of messages
SortKey string `q:"sort_key"`
// The key to sort a list of messages
SortDir string `q:"sort_dir"`
// The maximum number of messages to return
Limit int `q:"limit"`
}
// ToMessageListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToMessageListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
return q.String(), err
}
// List returns Messages optionally limited by the conditions provided in ListOpts.
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := listURL(client)
if opts != nil {
query, err := opts.ToMessageListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
return MessagePage{pagination.SinglePageBase(r)}
})
}
// Get retrieves the Message with the provided ID. To extract the Message
// object from the response, call the Extract method on the GetResult.
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
_, r.Err = client.Get(getURL(client, id), &r.Body, nil)
return
}