1 Star 1 Fork 0

teamlint/iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/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.Run(iris.Addr(":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!",
},
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/teamlint/iris.git
git@gitee.com:teamlint/iris.git
teamlint
iris
iris
v10.6.4

搜索帮助

0d507c66 1850385 C8b1a773 1850385