添加模板测试代码

This commit is contained in:
John
2018-11-09 17:48:57 +08:00
parent feaec67b71
commit 0d5d357857
4 changed files with 37 additions and 17 deletions

View File

@ -1,16 +0,0 @@
package main
import (
"gitee.com/johng/gf/g"
"gitee.com/johng/gf/g/net/ghttp"
)
func main() {
s := g.Server()
s.BindHandler("/", func(r *ghttp.Request){
content :=`{{if (get "name")}} {{get "name"}} {{else}} NoName {{end}}`
r.Response.WriteTplContent(content, nil)
})
s.SetPort(8199)
s.Run()
}

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{.title}}</title>
</head>
<body>
<H1>姓名 {{.name}}</H1>
12311
</body>
</html>

View File

@ -0,0 +1,23 @@
package main
import (
"gitee.com/johng/gf/g/frame/gmvc"
"gitee.com/johng/gf/g/net/ghttp"
)
type ControllerIndex struct {
gmvc.Controller
}
func (c *ControllerIndex) Info() {
c.View.Assign("title", "Go Frame 第一个网站")
c.View.Assigns(map[string]interface{}{
"name" : "很开心1",
"score" : 100,
})
c.View.Display("index.html")
}
func main() {
s := ghttp.GetServer()
s.BindController("/", new(ControllerIndex))
s.SetPort(8199)
s.Run()
}

View File

@ -1,5 +1,7 @@
package main
import "fmt"
func main() {
<- make(chan struct{})
fmt.Print(1)
}