(hostname string, domain models.DomainFields, path string, port int, useRandomPort bool)
| 56 | } |
| 57 | |
| 58 | func (routeActor routeActor) FindOrCreateRoute(hostname string, domain models.DomainFields, path string, port int, useRandomPort bool) (models.Route, error) { |
| 59 | var route models.Route |
| 60 | var err error |
| 61 | // if tcp route use random port should skip route lookup |
| 62 | if useRandomPort && domain.RouterGroupType == tcp { |
| 63 | err = new(errors.ModelNotFoundError) |
| 64 | } else { |
| 65 | route, err = routeActor.routeRepo.Find(hostname, domain, path, port) |
| 66 | } |
| 67 | |
| 68 | switch err.(type) { |
| 69 | case nil: |
| 70 | routeActor.ui.Say( |
| 71 | T("Using route {{.RouteURL}}", |
| 72 | map[string]interface{}{ |
| 73 | "RouteURL": terminal.EntityNameColor(route.URL()), |
| 74 | }), |
| 75 | ) |
| 76 | case *errors.ModelNotFoundError: |
| 77 | if useRandomPort && domain.RouterGroupType == tcp { |
| 78 | route, err = routeActor.CreateRandomTCPRoute(domain) |
| 79 | } else { |
| 80 | routeActor.ui.Say( |
| 81 | T("Creating route {{.Hostname}}...", |
| 82 | map[string]interface{}{ |
| 83 | "Hostname": terminal.EntityNameColor(domain.URLForHostAndPath(hostname, path, port)), |
| 84 | }), |
| 85 | ) |
| 86 | |
| 87 | route, err = routeActor.routeRepo.Create(hostname, domain, path, port, false) |
| 88 | } |
| 89 | |
| 90 | routeActor.ui.Ok() |
| 91 | routeActor.ui.Say("") |
| 92 | } |
| 93 | |
| 94 | return route, err |
| 95 | } |
| 96 | |
| 97 | func (routeActor routeActor) BindRoute(app models.Application, route models.Route) error { |
| 98 | if !app.HasRoute(route) { |
no test coverage detected