forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routing_api.go
43 lines (35 loc) · 997 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"
"github.com/cloudfoundry/cli/cf/configuration/coreconfig"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/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
}