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