1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 02:17:05 +00:00
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-08-15 12:17:48 +03:00
parent d0d7679a98
commit 8340285e7d
11 changed files with 105 additions and 11 deletions

View File

@@ -0,0 +1,30 @@
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()
test := app.Subdomain("test")
test.RegisterView(iris.HTML("./views", ".html").
Layout("layouts/test.layout.html"))
test.OnErrorCode(iris.StatusNotFound, handleNotFoundTestSubdomain)
test.Get("/", testIndex)
return app
}
func handleNotFoundTestSubdomain(ctx iris.Context) {
ctx.View("error.html", iris.Map{
"ErrorCode": ctx.GetStatusCode(),
})
}
func testIndex(ctx iris.Context) {
ctx.Writef("%s index page\n", ctx.Subdomain())
}

View File

@@ -0,0 +1,9 @@
<div style="background-color: black; color: red">
<h1>Oups, you've got an error!</h1>
{{ if .ErrorCode }}
{{ $tmplName := print "partials/" .ErrorCode ".html"}}
{{ render $tmplName }}
{{ else }}
{{ render "partials/500.html" }}
{{ end }}
</div>

View File

@@ -0,0 +1,3 @@
<div style="background-color: black; color: blue">
Index Page
</div>

View File

@@ -0,0 +1,12 @@
<html>
<head>
<title>Website Layout</title>
</head>
<body>
<h1>This is the global layout</h1>
<br />
<!-- Render the current template here -->
{{ yield }}
</body>
</html>

View File

@@ -0,0 +1,10 @@
<html>
<head>
<title>Test Subdomain</title>
</head>
<body>
<!-- Render the current template here -->
{{ yield }}
</body>
</html>

View File

@@ -0,0 +1,3 @@
<div style="background-color: white; color: red">
<h1>Not Found</h1>
</div>

View File

@@ -0,0 +1,3 @@
<div style="background-color: white; color: red">
<h1>Internal Server Error</h1>
</div>