mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
简化直接对模板内容的解析方法,完善TODO
This commit is contained in:
11
TODO
11
TODO
@ -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. 将模板变量进行暴露,以便应用端可以进行灵活控制;
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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("哈喽世界!")
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user