github.com/gophercloud/gophercloud@v1.11.0/openstack/sharedfilesystems/v2/messages/requests.go (about) 1 package messages 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // Delete will delete the existing Message with the provided ID. 9 func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { 10 resp, err := client.Delete(deleteURL(client, id), nil) 11 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 12 return 13 } 14 15 // ListOptsBuilder allows extensions to add additional parameters to the List 16 // request. 17 type ListOptsBuilder interface { 18 ToMessageListQuery() (string, error) 19 } 20 21 // ListOpts holds options for listing Messages. It is passed to the 22 // messages.List function. 23 type ListOpts struct { 24 // The message ID 25 ID string `q:"id"` 26 // The ID of the action during which the message was created 27 ActionID string `q:"action_id"` 28 // The ID of the message detail 29 DetailID string `q:"detail_id"` 30 // The message level 31 MessageLevel string `q:"message_level"` 32 // The UUID of the request during which the message was created 33 RequestID string `q:"request_id"` 34 // The UUID of the resource for which the message was created 35 ResourceID string `q:"resource_id"` 36 // The type of the resource for which the message was created 37 ResourceType string `q:"resource_type"` 38 // The key to sort a list of messages 39 SortKey string `q:"sort_key"` 40 // The key to sort a list of messages 41 SortDir string `q:"sort_dir"` 42 // The maximum number of messages to return 43 Limit int `q:"limit"` 44 } 45 46 // ToMessageListQuery formats a ListOpts into a query string. 47 func (opts ListOpts) ToMessageListQuery() (string, error) { 48 q, err := gophercloud.BuildQueryString(opts) 49 return q.String(), err 50 } 51 52 // List returns Messages optionally limited by the conditions provided in ListOpts. 53 func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { 54 url := listURL(client) 55 if opts != nil { 56 query, err := opts.ToMessageListQuery() 57 if err != nil { 58 return pagination.Pager{Err: err} 59 } 60 url += query 61 } 62 63 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 64 return MessagePage{pagination.SinglePageBase(r)} 65 }) 66 } 67 68 // Get retrieves the Message with the provided ID. To extract the Message 69 // object from the response, call the Extract method on the GetResult. 70 func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { 71 resp, err := client.Get(getURL(client, id), &r.Body, nil) 72 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 73 return 74 }