From 7d73e1080c89713b47a02a1be9022134eeea956b Mon Sep 17 00:00:00 2001 From: john Date: Wed, 5 Sep 2018 13:20:52 +0800 Subject: [PATCH] up --- g/net/ghttp/ghttp_response_view.go | 6 ++++++ geg/net/ghttp/server/template/tpl.go | 23 +++++++++++++++++++++ geg/os/gcfg/config.toml | 31 ++++++++++++++++++++++++++++ geg/os/gcfg/config.yml | 26 ----------------------- geg/os/gcfg/gcfg1.go | 6 +++--- geg/os/gcfg/memcache.yml | 1 + geg/os/gcfg/redis.toml | 20 ++++++++++++++++++ geg/os/gcfg/redis.yml | 14 ------------- 8 files changed, 84 insertions(+), 43 deletions(-) create mode 100644 geg/net/ghttp/server/template/tpl.go create mode 100644 geg/os/gcfg/config.toml delete mode 100644 geg/os/gcfg/config.yml create mode 100644 geg/os/gcfg/redis.toml delete mode 100644 geg/os/gcfg/redis.yml diff --git a/g/net/ghttp/ghttp_response_view.go b/g/net/ghttp/ghttp_response_view.go index 46a396612..f405699ba 100644 --- a/g/net/ghttp/ghttp_response_view.go +++ b/g/net/ghttp/ghttp_response_view.go @@ -62,6 +62,9 @@ func (r *Response) ParseTplContent(content string, params map[string]interface{} // 内置变量 func (r *Response) buildInVars(params map[string]interface{}) map[string]interface{} { + if params == nil { + params = make(map[string]interface{}) + } params["Config"] = gins.Config().GetMap("") params["Cookie"] = r.request.Cookie.Map() params["Session"] = r.request.Session.Data() @@ -70,6 +73,9 @@ func (r *Response) buildInVars(params map[string]interface{}) map[string]interfa // 内置函数 func (r *Response) buildInfuncs(funcmap map[string]interface{}) map[string]interface{} { + if funcmap == nil { + funcmap = make(map[string]interface{}) + } funcmap["get"] = r.funcGet funcmap["post"] = r.funcPost funcmap["request"] = r.funcRequest diff --git a/geg/net/ghttp/server/template/tpl.go b/geg/net/ghttp/server/template/tpl.go new file mode 100644 index 000000000..2948d268c --- /dev/null +++ b/geg/net/ghttp/server/template/tpl.go @@ -0,0 +1,23 @@ +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){ + content := + ` + {{if (get "name")}} + {{get "name"}} + {{else}} + NoName + {{end}} + ` + r.Response.WriteTplContent(content, nil) + }) + s.SetPort(8199) + s.Run() +} \ No newline at end of file diff --git a/geg/os/gcfg/config.toml b/geg/os/gcfg/config.toml new file mode 100644 index 000000000..7d211ff13 --- /dev/null +++ b/geg/os/gcfg/config.toml @@ -0,0 +1,31 @@ +# redis配置 +[[redis-cache]] + db = 0 + host = "192.168.0.100" + port = 6379 + +[[redis-cache]] + db = 1 + host = "192.168.0.100" + port = 6379 + +[[redis-disk]] + db = 0 + host = "192.168.0.100" + port = 6380 + +[[redis-disk]] + db = 1 + host = "192.168.0.100" + port = 6380 + +# memcache配置 +[[memcache]] + host = "192.168.0.101" + port = 11211 + expire = 60 + +[[memcache]] + host = "192.168.0.102" + port = 11211 + expire = 60 \ No newline at end of file diff --git a/geg/os/gcfg/config.yml b/geg/os/gcfg/config.yml deleted file mode 100644 index 3848021f8..000000000 --- a/geg/os/gcfg/config.yml +++ /dev/null @@ -1,26 +0,0 @@ -redis: - cache: - - host: 192.168.0.100 - port: 6379 - db: 0 - - host: 192.168.0.100 - port: 6379 - db: 1 - disk: - - host: 192.168.0.100 - port: 6380 - db: 0 - - host: 192.168.0.100 - port: 6380 - db: 1 - -memcache: - - host: 192.168.0.101 - port: 11211 - expire: 60 - - host: 192.168.0.102 - port: 11211 - expire: 60 - -viewpath : /home/www/templates/ -serverpath : /home/www/server/ \ No newline at end of file diff --git a/geg/os/gcfg/gcfg1.go b/geg/os/gcfg/gcfg1.go index 98a1b117e..a32caccdf 100644 --- a/geg/os/gcfg/gcfg1.go +++ b/geg/os/gcfg/gcfg1.go @@ -7,9 +7,9 @@ import ( func main() { c := gcfg.New("/home/john/Workspace/Go/GOPATH/src/gitee.com/johng/gf/geg/os/gcfg") - redisConfig := c.GetArray("redis-cache", "redis.yml") - memcacheConfig := c.GetArray("", "memcache.yml") + redisConfig := c.GetArray("redis-cache", "redis.toml") + memConfig := c.GetArray("", "memcache.yml") fmt.Println(redisConfig) - fmt.Println(memcacheConfig) + fmt.Println(memConfig) } diff --git a/geg/os/gcfg/memcache.yml b/geg/os/gcfg/memcache.yml index 1808acaec..056433dd1 100644 --- a/geg/os/gcfg/memcache.yml +++ b/geg/os/gcfg/memcache.yml @@ -1,3 +1,4 @@ +# memcache配置 - host: 192.168.0.101 port: 11211 expire: 60 diff --git a/geg/os/gcfg/redis.toml b/geg/os/gcfg/redis.toml new file mode 100644 index 000000000..61a45a64d --- /dev/null +++ b/geg/os/gcfg/redis.toml @@ -0,0 +1,20 @@ +# redis配置 +[[redis-cache]] + db = 0 + host = "192.168.0.100" + port = 6379 + +[[redis-cache]] + db = 1 + host = "192.168.0.100" + port = 6379 + +[[redis-disk]] + db = 0 + host = "192.168.0.100" + port = 6380 + +[[redis-disk]] + db = 1 + host = "192.168.0.100" + port = 6380 \ No newline at end of file diff --git a/geg/os/gcfg/redis.yml b/geg/os/gcfg/redis.yml deleted file mode 100644 index db0b6d79a..000000000 --- a/geg/os/gcfg/redis.yml +++ /dev/null @@ -1,14 +0,0 @@ -redis-cache: - - host: 192.168.0.100 - port: 6379 - db: 0 - - host: 192.168.0.100 - port: 6379 - db: 1 -redis-disk: - - host: 192.168.0.100 - port: 6380 - db: 0 - - host: 192.168.0.100 - port: 6380 - db: 1 \ No newline at end of file