mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
完善gcfg包使用示例
This commit is contained in:
@ -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
23
geg/os/gcfg/config.yml
Normal 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
15
geg/os/gcfg/gcfg1.go
Normal 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
13
geg/os/gcfg/gcfg2.go
Normal 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
6
geg/os/gcfg/memcache.yml
Normal 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
14
geg/os/gcfg/redis.yml
Normal 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
|
||||
Reference in New Issue
Block a user