forked from Kong/kubernetes-ingress-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
78 lines (65 loc) · 1.78 KB
/
service.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
package admin
import (
"encoding/json"
"net/url"
adminv1 "github.com/kong/kubernetes-ingress-controller/internal/apis/admin/v1"
)
type ServiceGetter interface {
Service() ServiceInterface
}
type ServiceInterface interface {
List(url.Values) (*adminv1.ServiceList, error)
Get(string) (*adminv1.Service, *APIResponse)
Create(*adminv1.Service) (*adminv1.Service, *APIResponse)
Patch(string, *adminv1.Service) (*adminv1.Service, *APIResponse)
Delete(string) error
}
type serviceAPI struct {
client APIInterface
}
func (a *serviceAPI) Create(service *adminv1.Service) (*adminv1.Service, *APIResponse) {
out := &adminv1.Service{}
err := a.client.Create(service, out)
return out, err
}
func (a *serviceAPI) Patch(id string, service *adminv1.Service) (*adminv1.Service, *APIResponse) {
out := &adminv1.Service{}
err := a.client.Patch(id, service, out)
return out, err
}
func (a *serviceAPI) Get(name string) (*adminv1.Service, *APIResponse) {
out := &adminv1.Service{}
err := a.client.Get(name, out)
return out, err
}
func (a *serviceAPI) List(params url.Values) (*adminv1.ServiceList, error) {
if params == nil {
params = url.Values{}
}
ServiceList := &adminv1.ServiceList{}
request := a.client.RestClient().Get().Resource("services")
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, ServiceList); err != nil {
return nil, err
}
if len(ServiceList.NextPage) > 0 {
params.Set("offset", ServiceList.Offset)
result, err := a.List(params)
if err != nil {
return nil, err
}
ServiceList.Items = append(ServiceList.Items, result.Items...)
}
return ServiceList, err
}
func (a *serviceAPI) Delete(id string) error {
return a.client.Delete(id)
}