Skip to content

Instantly share code, notes, and snippets.

@gnilchee
Created July 4, 2016 23:11
Show Gist options
  • Save gnilchee/219117e9bfb91ac29d82999afa53e775 to your computer and use it in GitHub Desktop.
Save gnilchee/219117e9bfb91ac29d82999afa53e775 to your computer and use it in GitHub Desktop.
HTTP server with registered subdomain and wildcard
package main
import (
"github.com/kataras/iris"
)
func main() {
// setting up atlas object
atlas := iris.New()
// catch wildcard subdomains
wildcard := atlas.Party("*.")
{
wildcard.Get("/", wildcardHandler)
}
//naked domain declared with listener below
atlas.Get("/", func(ctx *iris.Context) {
ctx.Write("Index, no subdomain")
})
atlas.Get("/ping", func(ctx *iris.Context) {
ctx.Write("pong")
})
//registered subdomain cv
cv := atlas.Party("cv.")
{
cv.Get("/", func(c *iris.Context) {
c.Write("Index of cv subdomain")
})
cv.Get("/ping", func(c *iris.Context) {
c.Write("pong from cv subdomain")
})
}
//listener and domain
atlas.Listen("mydomain.com:8080")
}
func wildcardHandler(ctx *iris.Context) {
stardotdomain := ctx.Subdomain()
ctx.Write("Subdomain: \"%s\" NOT FOUND", stardotdomain)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment