2020-08-15 11:17:48 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "github.com/kataras/iris/v12"
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
newApp().Listen("mydomain.com:80", iris.WithLogLevel("debug"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func newApp() *iris.Application {
|
|
|
|
app := iris.New()
|
|
|
|
|
2020-08-15 16:21:57 +02:00
|
|
|
// Create the "test.mydomain.com" subdomain.
|
2020-08-15 11:17:48 +02:00
|
|
|
test := app.Subdomain("test")
|
2020-08-15 16:21:57 +02:00
|
|
|
// Register views for the test subdomain.
|
2020-08-15 11:17:48 +02:00
|
|
|
test.RegisterView(iris.HTML("./views", ".html").
|
|
|
|
Layout("layouts/test.layout.html"))
|
|
|
|
|
2020-08-15 16:21:57 +02:00
|
|
|
// Optionally, to minify the HTML5 error response.
|
|
|
|
// Note that minification might be slower, caching is advised.
|
2020-08-16 06:07:36 +02:00
|
|
|
// test.UseError(iris.Minify)
|
|
|
|
// or pass it to OnErrorCode:
|
2020-08-15 16:21:57 +02:00
|
|
|
// Register error code 404 handler.
|
2020-08-16 06:07:36 +02:00
|
|
|
test.OnErrorCode(iris.StatusNotFound, iris.Minify, handleNotFoundTestSubdomain)
|
2020-08-15 16:21:57 +02:00
|
|
|
|
2020-08-15 11:17:48 +02:00
|
|
|
test.Get("/", testIndex)
|
|
|
|
|
|
|
|
return app
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleNotFoundTestSubdomain(ctx iris.Context) {
|
2022-12-13 00:37:15 +01:00
|
|
|
if err := ctx.View("error.html", iris.Map{
|
2020-08-15 11:17:48 +02:00
|
|
|
"ErrorCode": ctx.GetStatusCode(),
|
2022-12-13 00:37:15 +01:00
|
|
|
}); err != nil {
|
|
|
|
ctx.HTML("<h3>%s</h3>", err.Error())
|
|
|
|
return
|
|
|
|
}
|
2020-08-15 11:17:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func testIndex(ctx iris.Context) {
|
|
|
|
ctx.Writef("%s index page\n", ctx.Subdomain())
|
|
|
|
}
|