2018-10-26 08:15:29 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
2018-10-26 08:15:29 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
|
|
|
|
|
|
|
app.RegisterView(iris.HTML("./views", ".html").Layout("layout.html"))
|
|
|
|
// TIP: append .Reload(true) to reload the templates on each request.
|
|
|
|
|
|
|
|
app.Get("/home", func(ctx iris.Context) {
|
2019-01-19 23:00:54 +01:00
|
|
|
ctx.ViewData("title", "Home page")
|
2022-12-13 00:37:15 +01:00
|
|
|
if err := ctx.View("home.html"); err != nil {
|
|
|
|
ctx.HTML("<h3>%s</h3>", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-26 08:15:29 +02:00
|
|
|
// Note that: you can pass "layout" : "otherLayout.html" to bypass the config's Layout property
|
|
|
|
// or view.NoLayout to disable layout on this render action.
|
|
|
|
// third is an optional parameter
|
|
|
|
})
|
|
|
|
|
|
|
|
app.Get("/about", func(ctx iris.Context) {
|
2022-12-13 00:37:15 +01:00
|
|
|
if err := ctx.View("about.html"); err != nil {
|
|
|
|
ctx.HTML("<h3>%s</h3>", err.Error())
|
|
|
|
return
|
|
|
|
}
|
2018-10-26 08:15:29 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
app.Get("/user/index", func(ctx iris.Context) {
|
2022-12-13 00:37:15 +01:00
|
|
|
if err := ctx.View("user/index.html"); err != nil {
|
|
|
|
ctx.HTML("<h3>%s</h3>", err.Error())
|
|
|
|
return
|
|
|
|
}
|
2018-10-26 08:15:29 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
// http://localhost:8080
|
2020-03-05 21:41:27 +01:00
|
|
|
app.Listen(":8080")
|
2018-10-26 08:15:29 +02:00
|
|
|
}
|