-
Notifications
You must be signed in to change notification settings - Fork 929
/
routing_api.go
43 lines (35 loc) · 991 Bytes
/
routing_api.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
package api
import (
"fmt"
"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
"code.cloudfoundry.org/cli/cf/models"
"code.cloudfoundry.org/cli/cf/net"
)
type routingAPIRepository struct {
config coreconfig.Reader
gateway net.Gateway
}
//go:generate counterfeiter . RoutingAPIRepository
type RoutingAPIRepository interface {
ListRouterGroups(cb func(models.RouterGroup) bool) (apiErr error)
}
func NewRoutingAPIRepository(config coreconfig.Reader, gateway net.Gateway) RoutingAPIRepository {
return routingAPIRepository{
config: config,
gateway: gateway,
}
}
func (r routingAPIRepository) ListRouterGroups(cb func(models.RouterGroup) bool) (apiErr error) {
routerGroups := models.RouterGroups{}
endpoint := fmt.Sprintf("%s/v1/router_groups", r.config.RoutingAPIEndpoint())
apiErr = r.gateway.GetResource(endpoint, &routerGroups)
if apiErr != nil {
return apiErr
}
for _, router := range routerGroups {
if cb(router) == false {
return
}
}
return
}