forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routing_api.go
42 lines (35 loc) · 1 KB
/
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
package api
import (
"fmt"
"github.com/cloudfoundry/cli/cf/configuration/core_config"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/cli/cf/net"
)
type routingApiRepository struct {
config core_config.Reader
gateway net.Gateway
}
//go:generate counterfeiter -o fakes/fake_routing_api.go . RoutingApiRepository
type RoutingApiRepository interface {
ListRouterGroups(cb func(models.RouterGroup) bool) (apiErr error)
}
func NewRoutingApiRepository(config core_config.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
}