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