forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.go
59 lines (49 loc) · 876 Bytes
/
route.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
47
48
49
50
51
52
53
54
55
56
57
58
59
package models
import (
"fmt"
"net/url"
"strings"
)
type Route struct {
GUID string
Host string
Domain DomainFields
Path string
Port int
Space SpaceFields
Apps []ApplicationFields
ServiceInstance ServiceInstanceFields
}
func (r Route) URL() string {
return (&RoutePresenter{
Host: r.Host,
Domain: r.Domain.Name,
Path: r.Path,
Port: r.Port,
}).URL()
}
type RoutePresenter struct {
Host string
Domain string
Path string
Port int
}
func (r *RoutePresenter) URL() string {
var host string
if r.Host != "" {
host = r.Host + "." + r.Domain
} else {
host = r.Domain
}
if r.Port != 0 {
host = fmt.Sprintf("%s:%d", host, r.Port)
}
u := url.URL{
Host: host,
Path: r.Path,
}
return strings.TrimPrefix(u.String(), "//") // remove the empty scheme
}
type ManifestRoute struct {
Route string
}