Created
July 4, 2016 23:11
-
-
Save gnilchee/219117e9bfb91ac29d82999afa53e775 to your computer and use it in GitHub Desktop.
HTTP server with registered subdomain and wildcard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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