完善配置管理功能

This commit is contained in:
John 2018-01-04 11:59:35 +08:00
parent 3e2a3cf2f2
commit 48c2878885
3 changed files with 90 additions and 74 deletions

View File

@ -117,18 +117,6 @@ gf框架基于模块化设计实现了通用的HTTP/TCP/UDP Server并实
<!--
## 配置 ## 配置
1. 默认读取文件运行目录的config.json文件 1. 默认读取文件运行目录的config.json文件
1. 支持多配置文件管理,默认配置文件目录为当前运行目录; 1. 支持多配置文件管理,默认配置文件目录为当前运行目录;
@ -136,6 +124,16 @@ gf框架基于模块化设计实现了通用的HTTP/TCP/UDP Server并实
```json ```json
{ {
"viewpath" : "视图文件存放路径", "viewpath" : "视图文件存放路径",
"routings" : {
"dispatch" : {
"解析匹配规则1" : "解析替换规则1",
"解析匹配规则2" : "解析替换规则2"
},
"patch" : {
"打包匹配规则1" : "打包替换规则1",
"打包匹配规则2" : "打包替换规则2"
}
},
"database" : { "database" : {
"数据库分组名称" : [ "数据库分组名称" : [
{ {
@ -156,7 +154,12 @@ gf框架基于模块化设计实现了通用的HTTP/TCP/UDP Server并实
1. config.json示例文件 1. config.json示例文件
```json ```json
{ {
"viewpath" : "/home/john/Workspace/Go/gitee.com/johng/gf/geg/frame/mvc/view", "viewpath" : "/home/www/templates/",
"routines" : {
"dispatch" : {
"\/list\/page\/(\d+)[\/\?]*" : "/list?page=$1&"
}
},
"database" : { "database" : {
"default" : [ "default" : [
{ {
@ -198,4 +201,4 @@ gf框架基于模块化设计实现了通用的HTTP/TCP/UDP Server并实
} }
} }
``` ```
-->

View File

@ -12,6 +12,7 @@ import (
"gitee.com/johng/gf/g/container/gmap" "gitee.com/johng/gf/g/container/gmap"
"gitee.com/johng/gf/g/encoding/gjson" "gitee.com/johng/gf/g/encoding/gjson"
"sync" "sync"
"strings"
) )
const ( const (
@ -48,7 +49,10 @@ func (c *Config) filePath(files []string) string {
// 设置配置管理器的配置文件存放目录绝对路径 // 设置配置管理器的配置文件存放目录绝对路径
func (c *Config) SetPath(path string) { func (c *Config) SetPath(path string) {
c.mu.Lock() c.mu.Lock()
if strings.Compare(c.path, path) != 0 {
c.path = path c.path = path
c.jsons = gmap.NewStringInterfaceMap()
}
c.mu.Unlock() c.mu.Unlock()
} }

View File

@ -0,0 +1,9 @@
package demo
import "gitee.com/johng/gf/g/net/ghttp"
func init() {
ghttp.GetServer().BindHandler("/config", func (r *ghttp.Request) {
r.Response.WriteString("Apple")
})
}