forked from Kong/kubernetes-ingress-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.go
77 lines (65 loc) · 1.71 KB
/
route.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
package admin
import (
"encoding/json"
"net/url"
adminv1 "github.com/kong/kubernetes-ingress-controller/internal/apis/admin/v1"
)
type RouteGetter interface {
Route() RouteInterface
}
type RouteInterface interface {
List(url.Values) (*adminv1.RouteList, error)
Get(string) (*adminv1.Route, *APIResponse)
Create(*adminv1.Route) (*adminv1.Route, *APIResponse)
Patch(string, *adminv1.Route) (*adminv1.Route, *APIResponse)
Delete(string) error
}
type routeAPI struct {
client APIInterface
}
func (a *routeAPI) Create(route *adminv1.Route) (*adminv1.Route, *APIResponse) {
out := &adminv1.Route{}
err := a.client.Create(route, out)
return out, err
}
func (a *routeAPI) Patch(id string, route *adminv1.Route) (*adminv1.Route, *APIResponse) {
out := &adminv1.Route{}
err := a.client.Patch(id, route, out)
return out, err
}
func (a *routeAPI) Get(name string) (*adminv1.Route, *APIResponse) {
out := &adminv1.Route{}
err := a.client.Get(name, out)
return out, err
}
func (a *routeAPI) List(params url.Values) (*adminv1.RouteList, error) {
if params == nil {
params = url.Values{}
}
routeList := &adminv1.RouteList{}
request := a.client.RestClient().Get().Resource("routes")
for k, vals := range params {
for _, v := range vals {
request.Param(k, v)
}
}
data, err := request.DoRaw()
if err != nil {
return nil, err
}
if err := json.Unmarshal(data, routeList); err != nil {
return nil, err
}
if len(routeList.NextPage) > 0 {
params.Set("offset", routeList.Offset)
result, err := a.List(params)
if err != nil {
return nil, err
}
routeList.Items = append(routeList.Items, result.Items...)
}
return routeList, err
}
func (a *routeAPI) Delete(id string) error {
return a.client.Delete(id)
}