github.com/jasonkeene/cli@v6.14.1-0.20160816203908-ca5715166dfb+incompatible/cf/api/routing_api.go (about)

     1  package api
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/cloudfoundry/cli/cf/configuration/coreconfig"
     7  	"github.com/cloudfoundry/cli/cf/models"
     8  	"github.com/cloudfoundry/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  }