github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/cbr/v3/tasks/requests.go (about)

     1  package tasks
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  type ListOpts struct {
     9  	EndTime             string `q:"end_time"`
    10  	EnterpriseProjectId string `q:"enterprise_project_id"`
    11  	Limit               int    `q:"limit"`
    12  	Offset              int    `q:"offset"`
    13  	OperationType       string `q:"operation_type"`
    14  	ProviderId          string `q:"provider_id"`
    15  	ResourceId          string `q:"resource_id"`
    16  	ResourceName        string `q:"resource_name"`
    17  	StartTime           string `q:"start_time"`
    18  	Status              string `q:"status"`
    19  	VaultId             string `q:"vault_id"`
    20  	VaultName           string `q:"vault_name"`
    21  }
    22  
    23  type ListOptsBuilder interface {
    24  	ToTaskListQuery() (string, error)
    25  }
    26  
    27  func (opts ListOpts) ToTaskListQuery() (string, error) {
    28  	q, err := golangsdk.BuildQueryString(opts)
    29  	if err != nil {
    30  		return "", err
    31  	}
    32  	return q.String(), err
    33  }
    34  
    35  func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    36  	url := rootURL(client)
    37  	if opts != nil {
    38  		query, err := opts.ToTaskListQuery()
    39  		if err != nil {
    40  			return pagination.Pager{Err: err}
    41  		}
    42  		url += query
    43  	}
    44  
    45  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
    46  		return TaskPage{pagination.SinglePageBase(r)}
    47  	})
    48  }
    49  
    50  func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
    51  	_, r.Err = client.Get(resourceURL(client, id), &r.Body, nil)
    52  	return
    53  }