mirror of
https://github.com/kataras/iris.git
synced 2025-12-19 02:47:04 +00:00
reorganization of _examples and add some new examples such as iris+groupcache+mysql+docker
Former-commit-id: ed635ee95de7160cde11eaabc0c1dcb0e460a620
This commit is contained in:
49
_examples/caddy/server1/main.go
Normal file
49
_examples/caddy/server1/main.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/mvc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
templates := iris.HTML("./views", ".html").Layout("shared/layout.html")
|
||||
app.RegisterView(templates)
|
||||
|
||||
mvc.New(app).Handle(new(Controller))
|
||||
|
||||
// http://localhost:9091
|
||||
app.Listen(":9091")
|
||||
}
|
||||
|
||||
// Layout contains all the binding properties for the shared/layout.html
|
||||
type Layout struct {
|
||||
Title string
|
||||
}
|
||||
|
||||
// Controller is our example controller, request-scoped, each request has its own instance.
|
||||
type Controller struct {
|
||||
Layout Layout
|
||||
}
|
||||
|
||||
// BeginRequest is the first method fired when client requests from this Controller's root path.
|
||||
func (c *Controller) BeginRequest(ctx iris.Context) {
|
||||
c.Layout.Title = "Home Page"
|
||||
}
|
||||
|
||||
// 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) {}
|
||||
|
||||
// Get handles GET http://localhost:9091
|
||||
func (c *Controller) Get() mvc.View {
|
||||
return mvc.View{
|
||||
Name: "index.html",
|
||||
Data: iris.Map{
|
||||
"Layout": c.Layout,
|
||||
"Message": "Welcome to my website!",
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user