Joe Topjian | f61691c | 2016-11-05 12:34:59 -0600 | [diff] [blame] | 1 | package projects |
| 2 | |
| 3 | import ( |
| 4 | "github.com/gophercloud/gophercloud" |
| 5 | "github.com/gophercloud/gophercloud/pagination" |
| 6 | ) |
| 7 | |
| 8 | // ListOptsBuilder allows extensions to add additional parameters to |
| 9 | // the List request |
| 10 | type ListOptsBuilder interface { |
| 11 | ToProjectListQuery() (string, error) |
| 12 | } |
| 13 | |
| 14 | // ListOpts allows you to query the List method. |
| 15 | type ListOpts struct { |
| 16 | // DomainID filters the response by a domain ID. |
| 17 | DomainID string `q:"domain_id"` |
| 18 | |
| 19 | // Enabled filters the response by enabled projects. |
| 20 | Enabled *bool `q:"enabled"` |
| 21 | |
| 22 | // IsDomain filters the response by projects that are domains. |
| 23 | // Setting this to true is effectively listing domains. |
| 24 | IsDomain *bool `q:"is_domain"` |
| 25 | |
| 26 | // Name filters the response by project name. |
| 27 | Name string `q:"name"` |
| 28 | |
| 29 | // ParentID filters the response by projects of a given parent project. |
| 30 | ParentID string `q:"parent_id"` |
| 31 | } |
| 32 | |
| 33 | // ToProjectListQuery formats a ListOpts into a query string. |
| 34 | func (opts ListOpts) ToProjectListQuery() (string, error) { |
| 35 | q, err := gophercloud.BuildQueryString(opts) |
| 36 | return q.String(), err |
| 37 | } |
| 38 | |
| 39 | // List enumerats the Projects to which the current token has access. |
| 40 | func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { |
| 41 | url := listURL(client) |
| 42 | if opts != nil { |
| 43 | query, err := opts.ToProjectListQuery() |
| 44 | if err != nil { |
| 45 | return pagination.Pager{Err: err} |
| 46 | } |
| 47 | url += query |
| 48 | } |
| 49 | return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { |
| 50 | return ProjectPage{pagination.LinkedPageBase{PageResult: r}} |
| 51 | }) |
| 52 | } |