本文整理汇总了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())
}
}