github.com/lukasheimann/cloudfoundrycli@v7.1.0+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  func (client *Client) GetRouterGroups() ([]RouterGroup, error) {
    19  	request, err := client.newHTTPRequest(requestOptions{
    20  		RequestName: internal.GetRouterGroups,
    21  	})
    22  
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  	var routerGroups []RouterGroup
    27  
    28  	var response = Response{
    29  		Result: &routerGroups,
    30  	}
    31  
    32  	err = client.connection.Make(request, &response)
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  
    37  	return routerGroups, nil
    38  }
    39  
    40  // GetRouterGroupByName returns a list of RouterGroups.
    41  func (client *Client) GetRouterGroupByName(name string) (RouterGroup, error) {
    42  	request, err := client.newHTTPRequest(requestOptions{
    43  		RequestName: internal.GetRouterGroups,
    44  		Query:       url.Values{"name": []string{name}},
    45  	})
    46  
    47  	if err != nil {
    48  		return RouterGroup{}, err
    49  	}
    50  	var routerGroups []RouterGroup
    51  
    52  	var response = Response{
    53  		Result: &routerGroups,
    54  	}
    55  
    56  	err = client.connection.Make(request, &response)
    57  	if err != nil {
    58  		return RouterGroup{}, err
    59  	}
    60  
    61  	for _, routerGroup := range routerGroups {
    62  		if routerGroup.Name == name {
    63  			return routerGroup, nil
    64  		}
    65  	}
    66  
    67  	return RouterGroup{}, routererror.ResourceNotFoundError{}
    68  }