github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/api/routing_api.go (about) 1 package api 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 7 "code.cloudfoundry.org/cli/cf/models" 8 "code.cloudfoundry.org/cli/cf/net" 9 ) 10 11 type routingAPIRepository struct { 12 config coreconfig.Reader 13 gateway net.Gateway 14 } 15 16 //go:generate counterfeiter . RoutingAPIRepository 17 18 type RoutingAPIRepository interface { 19 ListRouterGroups(cb func(models.RouterGroup) bool) (apiErr error) 20 } 21 22 func NewRoutingAPIRepository(config coreconfig.Reader, gateway net.Gateway) RoutingAPIRepository { 23 return routingAPIRepository{ 24 config: config, 25 gateway: gateway, 26 } 27 } 28 29 func (r routingAPIRepository) ListRouterGroups(cb func(models.RouterGroup) bool) (apiErr error) { 30 routerGroups := models.RouterGroups{} 31 endpoint := fmt.Sprintf("%s/v1/router_groups", r.config.RoutingAPIEndpoint()) 32 apiErr = r.gateway.GetResource(endpoint, &routerGroups) 33 if apiErr != nil { 34 return apiErr 35 } 36 37 for _, router := range routerGroups { 38 if cb(router) == false { 39 return 40 } 41 } 42 return 43 }