MCPcopy Create free account
hub / github.com/kataras/iris / hostApp

Function hostApp

apps/switch_hosts.go:85–116  ·  view source on GitHub ↗
(host Host)

Source from the content-addressed store, hash-verified

83}
84
85func 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
118func hostFilter(expr string) iris.Filter {
119 regex := regexp.MustCompile(expr)

Callers 1

GetSwitchCasesMethod · 0.85

Calls 4

GetApplicationFunction · 0.92
newHostRedirectAppFunction · 0.85
MatchStringMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…