code.cloudfoundry.org/cli@v7.1.0+incompatible/cf/models/route.go (about)

     1  package models
     2  
     3  import (
     4  	"fmt"
     5  	"net/url"
     6  	"strings"
     7  )
     8  
     9  type Route struct {
    10  	GUID   string
    11  	Host   string
    12  	Domain DomainFields
    13  	Path   string
    14  	Port   int
    15  
    16  	Space           SpaceFields
    17  	Apps            []ApplicationFields
    18  	ServiceInstance ServiceInstanceFields
    19  }
    20  
    21  func (r Route) URL() string {
    22  	return (&RoutePresenter{
    23  		Host:   r.Host,
    24  		Domain: r.Domain.Name,
    25  		Path:   r.Path,
    26  		Port:   r.Port,
    27  	}).URL()
    28  }
    29  
    30  type RoutePresenter struct {
    31  	Host   string
    32  	Domain string
    33  	Path   string
    34  	Port   int
    35  }
    36  
    37  func (r *RoutePresenter) URL() string {
    38  	var host string
    39  	if r.Host != "" {
    40  		host = r.Host + "." + r.Domain
    41  	} else {
    42  		host = r.Domain
    43  	}
    44  
    45  	if r.Port != 0 {
    46  		host = fmt.Sprintf("%s:%d", host, r.Port)
    47  	}
    48  
    49  	u := url.URL{
    50  		Host: host,
    51  		Path: r.Path,
    52  	}
    53  
    54  	return strings.TrimPrefix(u.String(), "//") // remove the empty scheme
    55  }
    56  
    57  type ManifestRoute struct {
    58  	Route string
    59  }