本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/api/resources.RouteResource類的典型用法代碼示例。如果您正苦於以下問題:Golang RouteResource類的具體用法?Golang RouteResource怎麽用?Golang RouteResource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了RouteResource類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CreateInSpace
func (repo CloudControllerRouteRepository) CreateInSpace(host, path, domainGuid, spaceGuid string) (createdRoute models.Route, apiErr error) {
data := fmt.Sprintf(`{"host":"%s","path":"%s","domain_guid":"%s","space_guid":"%s"}`, host, path, domainGuid, spaceGuid)
resource := new(resources.RouteResource)
apiErr = repo.gateway.CreateResource(repo.config.ApiEndpoint(), "/v2/routes?inline-relations-depth=1", strings.NewReader(data), resource)
if apiErr != nil {
return
}
createdRoute = resource.ToModel()
return
}
示例2: CreateInSpace
func (repo CloudControllerRouteRepository) CreateInSpace(host, path, domainGUID, spaceGUID string, port int, randomPort bool) (models.Route, error) {
path = normalizedPath(path)
body := struct {
Host string `json:"host,omitempty"`
Path string `json:"path,omitempty"`
Port int `json:"port,omitempty"`
DomainGUID string `json:"domain_guid"`
SpaceGUID string `json:"space_guid"`
}{host, path, port, domainGUID, spaceGUID}
data, err := json.Marshal(body)
if err != nil {
return models.Route{}, err
}
q := struct {
GeneratePort bool `url:"generate_port,omitempty"`
InlineRelationsDepth int `url:"inline-relations-depth"`
}{randomPort, 1}
opt, _ := query.Values(q)
uriFragment := "/v2/routes?" + opt.Encode()
resource := new(resources.RouteResource)
err = repo.gateway.CreateResource(
repo.config.APIEndpoint(),
uriFragment,
bytes.NewReader(data),
resource,
)
if err != nil {
return models.Route{}, err
}
return resource.ToModel(), nil
}