简化直接对模板内容的解析方法,完善TODO

This commit is contained in:
John
2018-04-17 17:36:59 +08:00
parent aca2b335e0
commit 5419c494f2
5 changed files with 18 additions and 6 deletions

11
TODO
View File

@ -1,3 +1,12 @@
DONE:
1. gconv完善针对不同类型的判断例如尽量减少sprintf("%v", xxx)来执行string类型的转换
2. ghttp.Server请求执行中增加服务退出的方法不再执行后续操作
3. ghttp.Response对象完善并改进数据返回方法(Write/WriteString)
ON THE WAY:
1. gdb Where方法参数的改进研究是否可以将string参数类型修改为interface{}
2. 增加对于数据表Model的封装
3. ghttp.Server请求执行中增加服务退出的方法不再执行后续操作
3. ghttp.Server请求执行中增加服务退出的方法不再执行后续操作
4. 增加fsnotify包支持
5. 改进gcfg和gview的文件自动更新机制
6. 将模板变量进行暴露,以便应用端可以进行灵活控制;

View File

@ -55,9 +55,9 @@ func (view *View) Parse(file string) ([]byte, error) {
}
// 直接解析模板内容,并返回解析后的内容
func (view *View) ParseContent(name string, content string) ([]byte, error) {
func (view *View) ParseContent(content string) ([]byte, error) {
view.mu.RLock()
buffer, err := view.view.ParseContent(name, content, view.data)
buffer, err := view.view.ParseContent(content, view.data)
view.mu.RUnlock()
return buffer, err
}

View File

@ -26,7 +26,7 @@ func (p *utilpprof) Index(r *Request) {
}
if len(action) == 0 {
view := gins.View()
buffer, _ := view.ParseContent("ghttp_pprof", `
buffer, _ := view.ParseContent(`
<html>
<head>
<title>gf ghttp pprof</title>

View File

@ -16,6 +16,8 @@ import (
"gitee.com/johng/gf/g/os/gfile"
"gitee.com/johng/gf/g/container/gmap"
"gitee.com/johng/gf/g/container/gtype"
"gitee.com/johng/gf/g/encoding/ghash"
"gitee.com/johng/gf/g/util/gconv"
)
// 视图对象
@ -88,7 +90,8 @@ func (view *View) Parse(file string, params map[string]interface{}) ([]byte, err
}
// 直接解析模板内容,返回解析后的内容
func (view *View) ParseContent(name string, content string, params map[string]interface{}) ([]byte, error) {
func (view *View) ParseContent(content string, params map[string]interface{}) ([]byte, error) {
name := gconv.String(ghash.BKDRHash64([]byte(content)))
buffer := bytes.NewBuffer(nil)
if tpl, err := template.New(name).Funcs(view.getFuncs()).Parse(content); err != nil {
return nil, err

View File

@ -6,7 +6,7 @@ import (
func main() {
s := ghttp.GetServer()
s.EnablePprof("/debug/pprof2")
s.EnablePprof()
s.BindHandler("/", func(r *ghttp.Request){
r.Response.Writeln("哈喽世界!")
})