-
Notifications
You must be signed in to change notification settings - Fork 0
/
requests.go
98 lines (78 loc) · 2.31 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
89
90
91
92
93
94
95
96
97
98
package routes
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
type CreateOpts struct {
Type string `json:"type" required:"true"`
Nexthop string `json:"nexthop" required:"true"`
Destination string `json:"destination" required:"true"`
VpcID string `json:"vpc_id" required:"true"`
}
type CreateOptsBuilder interface {
ToRouteCreateMap() (map[string]interface{}, error)
}
func (opts CreateOpts) ToRouteCreateMap() (map[string]interface{}, error) {
b, err := gophercloud.BuildRequestBody(&opts, "route")
if err != nil {
return nil, err
}
return b, nil
}
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToRouteCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(CreateURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200, 201},
})
return
}
func Delete(client *gophercloud.ServiceClient, routeId string) (r DeleteResult) {
url := DeleteURL(client, routeId)
_, r.Err = client.Delete(url, nil)
return
}
func Get(client *gophercloud.ServiceClient, routeId string) (r GetResult) {
url := GetURL(client, routeId)
_, r.Err = client.Get(url, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
return
}
type ListOpts struct {
// Specifies that the port ID is used as the filter.
ID string `q:"id"`
Type string `q:"type"`
Destination string `q:"destination"`
VpcID string `q:"vpc_id"`
TenantID string `q:"tenant_id"`
// 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"`
}
type ListOptsBuilder interface {
ToListQuery() (string, error)
}
func (opts ListOpts) ToListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
return q.String(), err
}
func List(client *gophercloud.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 RoutePage{pagination.LinkedPageBase{PageResult: r}}
})
}