github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/iec/v1/cloudvolumes/requests.go (about)

     1  package cloudvolumes
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/huaweicloud/golangsdk"
     7  )
     8  
     9  func Get(client *golangsdk.ServiceClient, CloudVolumeID string) (r GetResult) {
    10  	url := GetURL(client, CloudVolumeID)
    11  	_, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{
    12  		OkCodes: []int{http.StatusOK},
    13  	})
    14  	return
    15  }
    16  
    17  func ListVolumeType(client *golangsdk.ServiceClient) (r GetResult) {
    18  	url := ListVolumeTypeURL(client)
    19  	_, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{
    20  		OkCodes: []int{http.StatusOK},
    21  	})
    22  	return
    23  }
    24  
    25  // ListOpts holds options for listing Voulmes. It is passed to the List
    26  // function.
    27  type ListOpts struct {
    28  	Limit  int    `q:"limit"`
    29  	Offset int    `q:"offset"`
    30  	Name   string `q:"name"`
    31  	Status string `q:"status"`
    32  }
    33  
    34  type ListOptsBuilder interface {
    35  	ToListVolumesQuery() (string, error)
    36  }
    37  
    38  func (opts ListOpts) ToListVolumesQuery() (string, error) {
    39  	b, err := golangsdk.BuildQueryString(&opts)
    40  	if err != nil {
    41  		return "", err
    42  	}
    43  	return b.String(), nil
    44  }
    45  
    46  func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) (r ListResult) {
    47  	listURL := rootURL(client)
    48  	if opts != nil {
    49  		query, err := opts.ToListVolumesQuery()
    50  		if err != nil {
    51  			r.Err = err
    52  			return r
    53  		}
    54  		listURL += query
    55  	}
    56  
    57  	_, r.Err = client.Get(listURL, &r.Body, &golangsdk.RequestOpts{
    58  		OkCodes: []int{http.StatusOK},
    59  	})
    60  	return
    61  }