本文整理匯總了Golang中cf/models.Application.HasRoute方法的典型用法代碼示例。如果您正苦於以下問題:Golang Application.HasRoute方法的具體用法?Golang Application.HasRoute怎麽用?Golang Application.HasRoute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cf/models.Application
的用法示例。
在下文中一共展示了Application.HasRoute方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: bindAppToRoute
func (cmd *Push) bindAppToRoute(app models.Application, params models.AppParams, c *cli.Context) {
if params.NoRoute {
if len(app.Routes) == 0 {
cmd.ui.Say("App %s is a worker, skipping route creation", terminal.EntityNameColor(app.Name))
} else {
for _, route := range app.Routes {
cmd.ui.Say("Removing route %s...", terminal.EntityNameColor(route.URL()))
cmd.routeRepo.Unbind(route.Guid, app.Guid)
}
}
return
}
routeFlagsPresent := c.String("n") != "" || c.String("d") != "" || c.Bool("no-hostname")
if len(app.Routes) > 0 && !routeFlagsPresent {
return
}
domain := cmd.findDomain(params)
hostname := cmd.hostnameForApp(params, c)
route, apiErr := cmd.routeRepo.FindByHostAndDomain(hostname, domain.Name)
switch apiErr.(type) {
case nil:
cmd.ui.Say("Using route %s", terminal.EntityNameColor(route.URL()))
case *errors.ModelNotFoundError:
cmd.ui.Say("Creating route %s...", terminal.EntityNameColor(domain.UrlForHost(hostname)))
route, apiErr = cmd.routeRepo.Create(hostname, domain.Guid)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
}
cmd.ui.Ok()
cmd.ui.Say("")
default:
cmd.ui.Failed(apiErr.Error())
}
if !app.HasRoute(route) {
cmd.ui.Say("Binding %s to %s...", terminal.EntityNameColor(domain.UrlForHost(hostname)), terminal.EntityNameColor(app.Name))
apiErr = cmd.routeRepo.Bind(route.Guid, app.Guid)
switch apiErr := apiErr.(type) {
case nil:
cmd.ui.Ok()
cmd.ui.Say("")
return
case errors.HttpError:
if apiErr.ErrorCode() == errors.INVALID_RELATION {
cmd.ui.Failed("The route %s is already in use.\nTIP: Change the hostname with -n HOSTNAME or use --random-route to generate a new route and then push again.", route.URL())
}
}
cmd.ui.Failed(apiErr.Error())
}
}