Joe Topjian | a08c1d2 | 2016-11-04 10:33:00 -0600 | [diff] [blame] | 1 | package limits |
| 2 | |
| 3 | import ( |
| 4 | "github.com/gophercloud/gophercloud" |
| 5 | ) |
| 6 | |
| 7 | // GetOptsBuilder allows extensions to add additional parameters to the |
| 8 | // Get request. |
| 9 | type GetOptsBuilder interface { |
| 10 | ToLimitsQuery() (string, error) |
| 11 | } |
| 12 | |
| 13 | // GetOpts enables retrieving limits by a specific tenant. |
| 14 | type GetOpts struct { |
| 15 | // The tenant ID to retrieve limits for |
| 16 | TenantID string `q:"tenant_id"` |
| 17 | } |
| 18 | |
| 19 | // ToLimitsQuery formats a GetOpts into a query string. |
| 20 | func (opts GetOpts) ToLimitsQuery() (string, error) { |
| 21 | q, err := gophercloud.BuildQueryString(opts) |
| 22 | return q.String(), err |
| 23 | } |
| 24 | |
| 25 | // Get returns the limits about the currently scoped tenant. |
| 26 | func Get(client *gophercloud.ServiceClient, opts GetOptsBuilder) (r GetResult) { |
| 27 | url := getURL(client) |
| 28 | if opts != nil { |
| 29 | query, err := opts.ToLimitsQuery() |
| 30 | if err != nil { |
| 31 | r.Err = err |
| 32 | return |
| 33 | } |
| 34 | url += query |
| 35 | } |
| 36 | |
| 37 | _, r.Err = client.Get(url, &r.Body, nil) |
| 38 | return |
| 39 | } |