2017-08-28 11:26:45 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/kataras/iris"
|
2017-12-20 07:33:53 +01:00
|
|
|
"github.com/kataras/iris/mvc"
|
2017-08-28 11:26:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
|
|
|
|
|
|
|
templates := iris.HTML("./views", ".html").Layout("shared/layout.html")
|
|
|
|
app.RegisterView(templates)
|
|
|
|
|
2017-12-20 07:33:53 +01:00
|
|
|
mvc.New(app).Register(new(Controller))
|
2017-08-28 11:26:45 +02:00
|
|
|
|
|
|
|
// http://localhost:9091
|
|
|
|
app.Run(iris.Addr(":9091"))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Layout contains all the binding properties for the shared/layout.html
|
|
|
|
type Layout struct {
|
|
|
|
Title string
|
|
|
|
}
|
|
|
|
|
2017-12-20 07:33:53 +01:00
|
|
|
// Controller is our example controller, request-scoped, each request has its own instance.
|
2017-08-28 11:26:45 +02:00
|
|
|
type Controller struct {
|
2017-12-20 07:33:53 +01:00
|
|
|
Layout Layout
|
2017-08-28 11:26:45 +02:00
|
|
|
}
|
|
|
|
|
2017-12-20 07:33:53 +01:00
|
|
|
// BeginRequest is the first method fired when client requests from this Controller's root path.
|
2017-08-28 11:26:45 +02:00
|
|
|
func (c *Controller) BeginRequest(ctx iris.Context) {
|
|
|
|
c.Layout.Title = "Home Page"
|
|
|
|
}
|
|
|
|
|
2017-12-20 07:33:53 +01:00
|
|
|
// EndRequest is the last method fired.
|
|
|
|
// It's here just to complete the BaseController
|
|
|
|
// in order to be tell iris to call the `BeginRequest` before the main method.
|
|
|
|
func (c *Controller) EndRequest(ctx iris.Context) {}
|
|
|
|
|
2017-08-28 11:26:45 +02:00
|
|
|
// Get handles GET http://localhost:9091
|
2017-12-20 07:33:53 +01:00
|
|
|
func (c *Controller) Get() mvc.View {
|
|
|
|
return mvc.View{
|
|
|
|
Name: "index.html",
|
|
|
|
Data: iris.Map{
|
|
|
|
"Layout": c.Layout,
|
|
|
|
"Message": "Welcome to my website!",
|
|
|
|
},
|
|
|
|
}
|
2017-08-28 11:26:45 +02:00
|
|
|
}
|