forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
router_group.go
46 lines (37 loc) · 1.04 KB
/
router_group.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
44
45
46
package router
import (
"net/url"
"code.cloudfoundry.org/cli/api/router/internal"
"code.cloudfoundry.org/cli/api/router/routererror"
)
// RouterGroup represents a router group.
type RouterGroup struct {
GUID string `json:"guid"`
Name string `json:"name"`
ReservablePorts string `json:"reservable_ports"`
Type string `json:"type"`
}
// GetRouterGroupByName returns a list of RouterGroups.
func (client *Client) GetRouterGroupByName(name string) (RouterGroup, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetRouterGroups,
Query: url.Values{"name": []string{name}},
})
if err != nil {
return RouterGroup{}, err
}
var routerGroups []RouterGroup
var response = Response{
Result: &routerGroups,
}
err = client.connection.Make(request, &response)
if err != nil {
return RouterGroup{}, err
}
for _, routerGroup := range routerGroups {
if routerGroup.Name == name {
return routerGroup, nil
}
}
return RouterGroup{}, routererror.ResourceNotFoundError{}
}