mirror of
https://gitee.com/johng/gf
synced 2026-07-05 21:32:17 +08:00
完善模板引擎热更新机制测试
This commit is contained in:
30
geg/os/gview/controller_hot_update.go
Normal file
30
geg/os/gview/controller_hot_update.go
Normal 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()
|
||||
}
|
||||
@ -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))
|
||||
@ -1 +1 @@
|
||||
test.tpl content
|
||||
test.tpl content2
|
||||
17
geg/os/gview/web_hot_update.go
Normal file
17
geg/os/gview/web_hot_update.go
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user