2020-08-05 05:46:45 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "github.com/kataras/iris/v12"
|
|
|
|
|
2020-09-05 07:56:01 +02:00
|
|
|
// $ go get -u github.com/go-bindata/go-bindata/...
|
2020-09-05 07:34:09 +02:00
|
|
|
// # OR: go get -u github.com/go-bindata/go-bindata/v3/go-bindata
|
|
|
|
// # to save it to your go.mod file
|
|
|
|
//
|
|
|
|
// $ go-bindata -fs -prefix "../template_blocks_0/views" ../template_blocks_0/views/...
|
2020-08-05 05:46:45 +02:00
|
|
|
// $ go run .
|
2020-09-05 07:34:09 +02:00
|
|
|
//
|
|
|
|
// # 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")
|
|
|
|
//
|
2020-08-05 05:46:45 +02:00
|
|
|
// System files are not used, you can optionally delete the folder and run the example now.
|
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
2020-09-05 07:34:09 +02:00
|
|
|
app.RegisterView(iris.Blocks(AssetFile(), ".html"))
|
2020-08-05 05:46:45 +02:00
|
|
|
|
|
|
|
app.Get("/", index)
|
|
|
|
app.Get("/500", internalServerError)
|
|
|
|
|
|
|
|
app.Listen(":8080")
|
|
|
|
}
|
|
|
|
|
|
|
|
func index(ctx iris.Context) {
|
|
|
|
data := iris.Map{
|
|
|
|
"Title": "Page Title",
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.ViewLayout("main")
|
|
|
|
ctx.View("index", data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func internalServerError(ctx iris.Context) {
|
|
|
|
ctx.StatusCode(iris.StatusInternalServerError)
|
|
|
|
|
|
|
|
data := iris.Map{
|
|
|
|
"Code": iris.StatusInternalServerError,
|
|
|
|
"Message": "Internal Server Error",
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.ViewLayout("error")
|
|
|
|
ctx.View("500", data)
|
|
|
|
}
|