This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
requests.go
88 lines (72 loc) · 2.25 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package bandwidths
import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)
func Get(client *golangsdk.ServiceClient, bandwidthId string) (r GetResult) {
url := GetURL(client, bandwidthId)
_, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
return
}
type ListOpts struct {
// Specifies the resource ID of pagination query. If the parameter
// is left blank, only resources on the first page are queried.
Marker string `q:"marker"`
// Specifies the number of records returned on each page.
Limit int `q:"limit"`
// enterprise_project_id
// You can use this field to filter the bandwidth under an enterprise project.
EnterpriseProjectId string `q:"enterprise_project_id"`
}
type ListOptsBuilder interface {
ToListQuery() (string, error)
}
func (opts ListOpts) ToListQuery() (string, error) {
q, err := golangsdk.BuildQueryString(opts)
return q.String(), err
}
func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := ListURL(client)
if opts != nil {
query, err := opts.ToListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
return pagination.NewPager(client, url,
func(r pagination.PageResult) pagination.Page {
return BandWidthPage{pagination.LinkedPageBase{PageResult: r}}
})
}
type UpdateOpts struct {
// Specifies the bandwidth name. The value is a string of 1 to 64
// characters that can contain letters, digits, underscores (_), and hyphens (-).
Name string `json:"name,omitempty"`
// Specifies the bandwidth size. The value ranges from 1 Mbit/s to
// 300 Mbit/s.
Size int `json:"size,omitempty"`
}
type UpdateOptsBuilder interface {
ToBandwidthsUpdateMap() (map[string]interface{}, error)
}
func (opts UpdateOpts) ToBandwidthsUpdateMap() (map[string]interface{}, error) {
b, err := golangsdk.BuildRequestBody(&opts, "bandwidth")
if err != nil {
return nil, err
}
return b, nil
}
func Update(client *golangsdk.ServiceClient, bandwidthId string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToBandwidthsUpdateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Put(UpdateURL(client, bandwidthId), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
return
}