-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
main.go
50 lines (41 loc) · 1.23 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import "github.com/kataras/iris/v12"
// $ go install github.com/go-bindata/go-bindata/v3/go-bindata@latest
//
// $ go-bindata -fs -prefix "../template_blocks_0/views" ../template_blocks_0/views/...
// $ go run .
//
// # OR: go-bindata -fs -prefix "views" ./views/... if the views dir is rel to the executable.
// # OR: go-bindata -fs -prefix "../template_blocks_0" ../template_blocks_0/views/...
// # with iris.Blocks(AssetFile()).RootDir("/views")
//
// System files are not used, you can optionally delete the folder and run the example now.
func main() {
app := iris.New()
app.RegisterView(iris.Blocks(AssetFile(), ".html"))
app.Get("/", index)
app.Get("/500", internalServerError)
app.Listen(":8080")
}
func index(ctx iris.Context) {
data := iris.Map{
"Title": "Page Title",
}
ctx.ViewLayout("main")
if err := ctx.View("index", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
return
}
}
func internalServerError(ctx iris.Context) {
ctx.StatusCode(iris.StatusInternalServerError)
data := iris.Map{
"Code": iris.StatusInternalServerError,
"Message": "Internal Server Error",
}
ctx.ViewLayout("error")
if err := ctx.View("500", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
return
}
}