2,190
社区成员
发帖
与我相关
我的任务
分享
app := iris.New()
//app.Use(recover.New())
//app.Use(iris.LimitRequestBodySize(1024 * 1024))
tmpl := iris.HTML("./views", ".html").
Layout("shared/layout.html").
Reload(true)
app.RegisterView(tmpl)
// registers a handler that serves HTTP requests
// with the contents of a file system (physical or embedded).
app.HandleDir("/content", "./content")
app.OnAnyErrorCode(func(ctx iris.Context) {
ctx.ViewData("Message", ctx.Values().
GetStringDefault("message", "The page you're looking for doesn't exist"))
ctx.View("shared/error.html")
})
//index := app.Party("/", middleware.CrsAuth()).AllowMethods(iris.MethodOptions)
index := mvc.New(app.Party("/"))
index.Handle(new(controller.IndexController))
//app.Get("/",controller.Index)
app.Run(
iris.Addr("localhost:8080"),
// Ignores err server closed log when CTRL/CMD+C pressed.
iris.WithoutServerError(iris.ErrServerClosed),
// Enables faster json serialization and more.
iris.WithOptimizations,
)
type IndexController struct {
Ctx iris.Context
}
var indexView = mvc.View{
Name: "index.html",
//Data: iris.Map{"msg": "Hello Index", "title": "page index",},
}
func (i *IndexController) Get() mvc.Result {
//i.Ctx.ViewLayout(iris.NoLayout)
return indexView
}
func Index(ctx iris.Context) {
//ctx.ViewData("msg", "Hello Index")
//ctx.ViewData("title", "Hello Index")
ctx.View("index.html")
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0"/>
<link rel="stylesheet" type="text/css" href="/content/style/site.css"/>
</head>
<body>
{{ render "shared/_top.html"}}
<div>
{{ yield }}
</div>
</body>
</html>
{{ define "index-title"}}
<title>{{.title}}</title>
{{ end }}
<div style="width: 100%; height: 100%; background-color: #ffffff">
<h1>{{.msg}}}</h1>
</div>