Ejemplo n.º 1
0
func (routeActor RouteActor) BindRoute(app models.Application, route models.Route) {
	if !app.HasRoute(route) {
		routeActor.ui.Say(T("Binding {{.URL}} to {{.AppName}}...", map[string]interface{}{"URL": terminal.EntityNameColor(route.URL()), "AppName": terminal.EntityNameColor(app.Name)}))

		apiErr := routeActor.routeRepo.Bind(route.Guid, app.Guid)
		switch apiErr := apiErr.(type) {
		case nil:
			routeActor.ui.Ok()
			routeActor.ui.Say("")
			return
		case errors.HttpError:
			if apiErr.ErrorCode() == errors.INVALID_RELATION {
				routeActor.ui.Failed(T("The route {{.URL}} is already in use.\nTIP: Change the hostname with -n HOSTNAME or use --random-route to generate a new route and then push again.", map[string]interface{}{"URL": route.URL()}))
			}
		}
		routeActor.ui.Failed(apiErr.Error())
	}
}