-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathvhost.go
More file actions
20 lines (17 loc) · 604 Bytes
/
vhost.go
File metadata and controls
20 lines (17 loc) · 604 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: © 2015 LabStack LLC and Echo contributors
package echo
import "net/http"
// NewVirtualHostHandler creates instance of Echo that routes requests to given virtual hosts
// when hosts in request does not exist in given map the request is served by returned Echo instance.
func NewVirtualHostHandler(vhosts map[string]*Echo) *Echo {
e := New()
e.serveHTTPFunc = func(w http.ResponseWriter, r *http.Request) {
if vh, ok := vhosts[r.Host]; ok {
vh.ServeHTTP(w, r)
return
}
e.serveHTTP(w, r) // unknown host in request
}
return e
}