github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/ces/v1/metrics/requests.go (about) 1 package metrics 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // ListOptsBuilder allows extensions to add additional parameters to the 9 // List request. 10 type ListOptsBuilder interface { 11 ToMetricsListMap() (string, error) 12 } 13 14 //ListOpts allows the filtering and sorting of paginated collections through the API. 15 type ListOpts struct { 16 // Specifies the namespace. 17 Namespace string `q:"namespace"` 18 19 // The value ranges from 1 to 1000, and is 1000 by default. 20 // This parameter is used to limit the number of query results. 21 Limit *int `q:"limit"` 22 23 // Specifies the metric name. 24 MetricName string `q:"metric_name"` 25 26 // Specifies the metric dimension. 27 // A maximum of three dimensions are supported, and the dimensions are numbered from 0 in dim. 28 Dim0 string `q:"dim.0"` 29 Dim1 string `q:"dim.1"` 30 Dim2 string `q:"dim.2"` 31 32 // Specifies the paging start value. 33 Start string `q:"start"` 34 35 // Specifies the sorting order of query results. 36 Order string `q:"order"` 37 } 38 39 // ToMetricsListMap formats a ListOpts into a query string. 40 func (opts ListOpts) ToMetricsListMap() (string, error) { 41 s, err := golangsdk.BuildQueryString(opts) 42 if err != nil { 43 return "", err 44 } 45 return s.String(), err 46 } 47 48 //Get the Metric List 49 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 50 url := getMetricsURL(client) 51 if opts != nil { 52 query, err := opts.ToMetricsListMap() 53 if err != nil { 54 return pagination.Pager{Err: err} 55 } 56 url += query 57 } 58 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 59 return MetricsPage{pagination.LinkedPageBase{PageResult: r}} 60 }) 61 }