This commit is contained in:
john
2018-09-05 13:20:52 +08:00
parent ab4e6109f5
commit 7d73e1080c
8 changed files with 84 additions and 43 deletions

View File

@ -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

View File

@ -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()
}

31
geg/os/gcfg/config.toml Normal file
View File

@ -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

View File

@ -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/

View File

@ -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)
}

View File

@ -1,3 +1,4 @@
# memcache配置
- host: 192.168.0.101
port: 11211
expire: 60

20
geg/os/gcfg/redis.toml Normal file
View File

@ -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

View File

@ -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