forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_route_group_client.sk.go
123 lines (103 loc) · 3.66 KB
/
http_route_group_client.sk.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Code generated by solo-kit. DO NOT EDIT.
package v1alpha1
import (
"github.com/solo-io/solo-kit/pkg/api/v1/clients"
"github.com/solo-io/solo-kit/pkg/api/v1/clients/factory"
"github.com/solo-io/solo-kit/pkg/api/v1/resources"
"github.com/solo-io/solo-kit/pkg/errors"
)
type HTTPRouteGroupWatcher interface {
// watch namespace-scoped httproutegroups
Watch(namespace string, opts clients.WatchOpts) (<-chan HTTPRouteGroupList, <-chan error, error)
}
type HTTPRouteGroupClient interface {
BaseClient() clients.ResourceClient
Register() error
Read(namespace, name string, opts clients.ReadOpts) (*HTTPRouteGroup, error)
Write(resource *HTTPRouteGroup, opts clients.WriteOpts) (*HTTPRouteGroup, error)
Delete(namespace, name string, opts clients.DeleteOpts) error
List(namespace string, opts clients.ListOpts) (HTTPRouteGroupList, error)
HTTPRouteGroupWatcher
}
type hTTPRouteGroupClient struct {
rc clients.ResourceClient
}
func NewHTTPRouteGroupClient(rcFactory factory.ResourceClientFactory) (HTTPRouteGroupClient, error) {
return NewHTTPRouteGroupClientWithToken(rcFactory, "")
}
func NewHTTPRouteGroupClientWithToken(rcFactory factory.ResourceClientFactory, token string) (HTTPRouteGroupClient, error) {
rc, err := rcFactory.NewResourceClient(factory.NewResourceClientParams{
ResourceType: &HTTPRouteGroup{},
Token: token,
})
if err != nil {
return nil, errors.Wrapf(err, "creating base HTTPRouteGroup resource client")
}
return NewHTTPRouteGroupClientWithBase(rc), nil
}
func NewHTTPRouteGroupClientWithBase(rc clients.ResourceClient) HTTPRouteGroupClient {
return &hTTPRouteGroupClient{
rc: rc,
}
}
func (client *hTTPRouteGroupClient) BaseClient() clients.ResourceClient {
return client.rc
}
func (client *hTTPRouteGroupClient) Register() error {
return client.rc.Register()
}
func (client *hTTPRouteGroupClient) Read(namespace, name string, opts clients.ReadOpts) (*HTTPRouteGroup, error) {
opts = opts.WithDefaults()
resource, err := client.rc.Read(namespace, name, opts)
if err != nil {
return nil, err
}
return resource.(*HTTPRouteGroup), nil
}
func (client *hTTPRouteGroupClient) Write(hTTPRouteGroup *HTTPRouteGroup, opts clients.WriteOpts) (*HTTPRouteGroup, error) {
opts = opts.WithDefaults()
resource, err := client.rc.Write(hTTPRouteGroup, opts)
if err != nil {
return nil, err
}
return resource.(*HTTPRouteGroup), nil
}
func (client *hTTPRouteGroupClient) Delete(namespace, name string, opts clients.DeleteOpts) error {
opts = opts.WithDefaults()
return client.rc.Delete(namespace, name, opts)
}
func (client *hTTPRouteGroupClient) List(namespace string, opts clients.ListOpts) (HTTPRouteGroupList, error) {
opts = opts.WithDefaults()
resourceList, err := client.rc.List(namespace, opts)
if err != nil {
return nil, err
}
return convertToHTTPRouteGroup(resourceList), nil
}
func (client *hTTPRouteGroupClient) Watch(namespace string, opts clients.WatchOpts) (<-chan HTTPRouteGroupList, <-chan error, error) {
opts = opts.WithDefaults()
resourcesChan, errs, initErr := client.rc.Watch(namespace, opts)
if initErr != nil {
return nil, nil, initErr
}
httproutegroupsChan := make(chan HTTPRouteGroupList)
go func() {
for {
select {
case resourceList := <-resourcesChan:
httproutegroupsChan <- convertToHTTPRouteGroup(resourceList)
case <-opts.Ctx.Done():
close(httproutegroupsChan)
return
}
}
}()
return httproutegroupsChan, errs, nil
}
func convertToHTTPRouteGroup(resources resources.ResourceList) HTTPRouteGroupList {
var hTTPRouteGroupList HTTPRouteGroupList
for _, resource := range resources {
hTTPRouteGroupList = append(hTTPRouteGroupList, resource.(*HTTPRouteGroup))
}
return hTTPRouteGroupList
}