github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/api/router/router_group.go (about)

     1  package router
     2  
     3  import (
     4  	"net/url"
     5  
     6  	"code.cloudfoundry.org/cli/api/router/internal"
     7  	"code.cloudfoundry.org/cli/api/router/routererror"
     8  )
     9  
    10  // RouterGroup represents a router group.
    11  type RouterGroup struct {
    12  	GUID            string `json:"guid"`
    13  	Name            string `json:"name"`
    14  	ReservablePorts string `json:"reservable_ports"`
    15  	Type            string `json:"type"`
    16  }
    17  
    18  // GetRouterGroupByName returns a list of RouterGroups.
    19  func (client *Client) GetRouterGroupByName(name string) (RouterGroup, error) {
    20  	request, err := client.newHTTPRequest(requestOptions{
    21  		RequestName: internal.GetRouterGroups,
    22  		Query:       url.Values{"name": []string{name}},
    23  	})
    24  
    25  	if err != nil {
    26  		return RouterGroup{}, err
    27  	}
    28  	var routerGroups []RouterGroup
    29  
    30  	var response = Response{
    31  		Result: &routerGroups,
    32  	}
    33  
    34  	err = client.connection.Make(request, &response)
    35  	if err != nil {
    36  		return RouterGroup{}, err
    37  	}
    38  
    39  	for _, routerGroup := range routerGroups {
    40  		if routerGroup.Name == name {
    41  			return routerGroup, nil
    42  		}
    43  	}
    44  
    45  	return RouterGroup{}, routererror.ResourceNotFoundError{}
    46  }