完善模板引擎热更新机制测试

This commit is contained in:
John
2018-05-15 13:53:13 +08:00
parent ef9cfcf759
commit 9ce65c195a
4 changed files with 51 additions and 4 deletions

View File

@ -0,0 +1,30 @@
package main
import (
"gitee.com/johng/gf/g"
"gitee.com/johng/gf/g/frame/gmvc"
)
func init() {
g.View().SetPath(`D:\Workspace\Go\GOPATH\src\gitee.com\johng\gf\geg\os\gview`)
}
// 测试控制器注册模板热更新机制
type Controller struct {
gmvc.Controller
}
// 测试模板热更新机制
func (c *Controller) Test() {
b, _ := c.View.Parse("test.tpl")
c.Response.Write(b)
}
func main() {
s := g.Server()
s.BindController("/", &Controller{})
s.Run()
}

View File

@ -4,13 +4,13 @@ package main
import (
"fmt"
"time"
"gitee.com/johng/gf/g"
"gitee.com/johng/gf/g/os/gtime"
"gitee.com/johng/gf/g/frame/gins"
)
func main() {
v := gins.View()
v.SetPath("/home/john/Workspace/Go/GOPATH/src/gitee.com/johng/gf/geg/os/gview")
v := g.View()
v.SetPath(`D:\Workspace\Go\GOPATH\src\gitee.com\johng\gf\geg\os\gview`)
gtime.SetInterval(time.Second, func() bool {
b, _ := v.Parse("test.tpl", nil)
fmt.Println(string(b))

View File

@ -1 +1 @@
test.tpl content
test.tpl content2

View File

@ -0,0 +1,17 @@
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) {
g.View().SetPath(`D:\Workspace\Go\GOPATH\src\gitee.com\johng\gf\geg\os\gview`)
b, _ := g.View().Parse("test.tpl", nil)
r.Response.Write(b)
})
s.Run()
}