完善gcfg包使用示例

This commit is contained in:
John
2018-04-10 15:36:35 +08:00
parent 067c07903c
commit 3b31fda887
6 changed files with 75 additions and 1 deletions

View File

@ -411,10 +411,13 @@ func (j *Json) Get(pattern string) interface{} {
// 根据pattern层级查找变量指针
func (j *Json) getPointerByPattern(pattern string) *interface{} {
start := 0
index := len(pattern)
start := 0
length := 0
pointer := j.p
if index == 0 {
return pointer
}
for {
if r := j.checkPatternByPointer(pattern[start:index], pointer); r != nil {
length += index - start

23
geg/os/gcfg/config.yml Normal file
View File

@ -0,0 +1,23 @@
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

15
geg/os/gcfg/gcfg1.go Normal file
View File

@ -0,0 +1,15 @@
package main
import (
"fmt"
"gitee.com/johng/gf/g/os/gcfg"
)
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")
fmt.Println(redisConfig)
fmt.Println(memcacheConfig)
}

13
geg/os/gcfg/gcfg2.go Normal file
View File

@ -0,0 +1,13 @@
package main
import (
"fmt"
"gitee.com/johng/gf/g/os/gcfg"
)
func main() {
c := gcfg.New("/home/john/Workspace/Go/GOPATH/src/gitee.com/johng/gf/geg/os/gcfg")
v := c.GetArray("memcache")
fmt.Println(v)
}

6
geg/os/gcfg/memcache.yml Normal file
View File

@ -0,0 +1,6 @@
- host: 192.168.0.101
port: 11211
expire: 60
- host: 192.168.0.102
port: 11211
expire: 60

14
geg/os/gcfg/redis.yml Normal file
View File

@ -0,0 +1,14 @@
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