github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/compute/v2/limits/requests.go (about) 1 package limits 2 3 import ( 4 "context" 5 6 "github.com/vnpaycloud-console/gophercloud/v2" 7 ) 8 9 // GetOptsBuilder allows extensions to add additional parameters to the 10 // Get request. 11 type GetOptsBuilder interface { 12 ToLimitsQuery() (string, error) 13 } 14 15 // GetOpts enables retrieving limits by a specific tenant. 16 type GetOpts struct { 17 // The tenant ID to retrieve limits for. 18 TenantID string `q:"tenant_id"` 19 } 20 21 // ToLimitsQuery formats a GetOpts into a query string. 22 func (opts GetOpts) ToLimitsQuery() (string, error) { 23 q, err := gophercloud.BuildQueryString(opts) 24 return q.String(), err 25 } 26 27 // Get returns the limits about the currently scoped tenant. 28 func Get(ctx context.Context, client *gophercloud.ServiceClient, opts GetOptsBuilder) (r GetResult) { 29 url := getURL(client) 30 if opts != nil { 31 query, err := opts.ToLimitsQuery() 32 if err != nil { 33 r.Err = err 34 return 35 } 36 url += query 37 } 38 39 resp, err := client.Get(ctx, url, &r.Body, nil) 40 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 41 return 42 }