diff --git a/g/net/ghttp/ghttp_response_view.go b/g/net/ghttp/ghttp_response_view.go index acb1c30a9..8b2b63eb1 100644 --- a/g/net/ghttp/ghttp_response_view.go +++ b/g/net/ghttp/ghttp_response_view.go @@ -65,7 +65,6 @@ func (r *Response) buildInVars(params map[string]interface{}) map[string]interfa if params == nil { params = make(map[string]interface{}) } - c := gins.Config() if c.GetFilePath() != "" { params["Config"] = c.GetMap("") diff --git a/g/os/gcfg/gcfg.go b/g/os/gcfg/gcfg.go index 7a606b85b..906a8eff8 100644 --- a/g/os/gcfg/gcfg.go +++ b/g/os/gcfg/gcfg.go @@ -63,13 +63,8 @@ func (c *Config) filePath(file...string) (path string) { } c.paths.RLockFunc(func(array []string) { for _, v := range array { - //fmt.Println("search:", v, name) if path, _ = gspath.Search(v, name); path != "" { break - } else { - //if strings.EqualFold(v, "/Users/john/Temp/config") { - // gutil.Dump(gspath.Get(v).AllPaths()) - //} } } }) @@ -94,6 +89,10 @@ func (c *Config) SetPath(path string) error { glog.Error(fmt.Sprintf(`[gcfg] SetPath failed: %s`, err.Error())) return err } + // 重复判断 + if c.paths.Search(realPath) != -1 { + return nil + } c.jsons.Clear() c.paths.Clear() c.paths.Append(realPath) @@ -116,14 +115,29 @@ func (c *Config) AddPath(path string) error { glog.Error(fmt.Sprintf(`[gcfg] AddPath failed: %s`, err.Error())) return err } + // 重复判断 + if c.paths.Search(realPath) != -1 { + return nil + } c.paths.Append(realPath) glog.Debug("[gcfg] AddPath:", realPath) return nil } -// 获取指定文件的绝对路径,默认获取默认的配置文件路径 -func (c *Config) GetFilePath(file...string) string { - return c.filePath(file...) +// 获取指定文件的绝对路径,默认获取默认的配置文件路径,当指定的配置文件不存在时,返回空字符串,并且不会报错。 +func (c *Config) GetFilePath(file...string) (path string) { + name := c.name.Val() + if len(file) > 0 { + name = file[0] + } + c.paths.RLockFunc(func(array []string) { + for _, v := range array { + if path, _ = gspath.Search(v, name); path != "" { + break + } + } + }) + return } // 设置配置管理对象的默认文件名称 diff --git a/g/os/gview/gview.go b/g/os/gview/gview.go index ba813bcd1..ee51bda83 100644 --- a/g/os/gview/gview.go +++ b/g/os/gview/gview.go @@ -115,6 +115,10 @@ func (view *View) SetPath(path string) error { glog.Error(fmt.Sprintf(`[gview] SetPath failed: %s`, err.Error())) return err } + // 重复判断 + if view.paths.Search(realPath) != -1 { + return nil + } view.paths.Clear() view.paths.Append(realPath) glog.Debug("[gview] SetPath:", realPath) @@ -132,6 +136,10 @@ func (view *View) AddPath(path string) error { glog.Error(fmt.Sprintf(`[gview] AddPath failed: %s`, err.Error())) return err } + // 重复判断 + if view.paths.Search(realPath) != -1 { + return nil + } view.paths.Append(realPath) glog.Debug("[gview] AddPath:", realPath) return nil diff --git a/geg/net/ghttp/server/template/layout/main.go b/geg/net/ghttp/server/template/layout/main.go new file mode 100644 index 000000000..809376b66 --- /dev/null +++ b/geg/net/ghttp/server/template/layout/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "github.com/gogf/gf/g" + "github.com/gogf/gf/g/net/ghttp" +) + +func main() { + s := g.Server() + s.BindHandler("/main1", func(r *ghttp.Request) { + r.Response.WriteTpl("layout.html", g.Map{ + "mainTpl" : "main/main1.html", + }) + }) + s.BindHandler("/main2", func(r *ghttp.Request) { + r.Response.WriteTpl("layout.html", g.Map{ + "mainTpl" : "main/main2.html", + }) + }) + g.View().SetPath("template") + s.SetPort(8199) + s.Run() +} diff --git a/geg/net/ghttp/server/template/layout/template/footer.html b/geg/net/ghttp/server/template/layout/template/footer.html new file mode 100644 index 000000000..83ae25b65 --- /dev/null +++ b/geg/net/ghttp/server/template/layout/template/footer.html @@ -0,0 +1 @@ +