github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/compute/v2/extensions/limits/requests.go (about)

     1  package limits
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     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 := golangsdk.BuildQueryString(opts)
    22  	if err != nil {
    23  		return "", err
    24  	}
    25  	return q.String(), err
    26  }
    27  
    28  // Get returns the limits about the currently scoped tenant.
    29  func Get(client *golangsdk.ServiceClient, opts GetOptsBuilder) (r GetResult) {
    30  	url := getURL(client)
    31  	if opts != nil {
    32  		query, err := opts.ToLimitsQuery()
    33  		if err != nil {
    34  			r.Err = err
    35  			return
    36  		}
    37  		url += query
    38  	}
    39  
    40  	_, r.Err = client.Get(url, &r.Body, nil)
    41  	return
    42  }