buaazp / fasthttprouter

A high performance fasthttp request router that scales well

Home Page:http://godoc.org/github.com/buaazp/fasthttprouter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling subdomains

dgrr opened this issue · comments

How this library can handle subdomains like cloud.dmester.xyz or similar?
Or directly domains like dmester.xyz or librelabua.org in the same program without needing reverse proxy or similar.

Something like this:

func main() {
	clouddmesterxyz := fasthttprouter.New()
	clouddmesterxyz.GET("/", clouddmesterxyzIndex)

	dmesterxyz := fasthttprouter.New()
	dmesterxyz.GET("/", dmesterxyzIndex)

	clouddmesterxyzHost := []byte("cloud.dmester.xyz")

	log.Fatal(fasthttp.ListenAndServe(":8080", func(ctx *fasthttp.RequestCtx) {
		if bytes.Equal(ctx.Host(), clouddmesterxyzHost) {
			clouddmesterxyz.Handler(ctx)
		} else {
			dmesterxyz.Handler(ctx)
		}
	})
}