(host Host)
| 83 | } |
| 84 | |
| 85 | func hostApp(host Host) *iris.Application { |
| 86 | if host.Target == nil { |
| 87 | return nil |
| 88 | } |
| 89 | |
| 90 | switch target := host.Target.(type) { |
| 91 | case context.Application: |
| 92 | return target.(*iris.Application) |
| 93 | case string: |
| 94 | // Check if the given target is an application name, if so |
| 95 | // we must not redirect (loop) we must serve the request |
| 96 | // using that app. |
| 97 | if targetApp, ok := context.GetApplication(target); ok { |
| 98 | // It's always iris.Application so we are totally safe here. |
| 99 | return targetApp.(*iris.Application) |
| 100 | } |
| 101 | // If it's a real host, warn the user of invalid input. |
| 102 | u, err := url.Parse(target) |
| 103 | if err == nil && u.IsAbs() { |
| 104 | // remember, we redirect hosts, not full URLs here. |
| 105 | panic(fmt.Sprintf(`iris: switch: hosts: invalid target host: "%s"`, target)) |
| 106 | } |
| 107 | |
| 108 | if regex := regexp.MustCompile(host.Pattern); regex.MatchString(target) { |
| 109 | panic(fmt.Sprintf(`iris: switch: hosts: loop detected between expression: "%s" and target host: "%s"`, host.Pattern, host.Target)) |
| 110 | } |
| 111 | |
| 112 | return newHostRedirectApp(target, HostsRedirectCode) |
| 113 | default: |
| 114 | panic(fmt.Sprintf("iris: switch: hosts: invalid target type: %T", target)) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | func hostFilter(expr string) iris.Filter { |
| 119 | regex := regexp.MustCompile(expr) |
no test coverage detected
searching dependent graphs…