mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 03:07:45 +08:00
完善配置管理功能
This commit is contained in:
parent
3e2a3cf2f2
commit
48c2878885
31
README.MD
31
README.MD
@ -117,18 +117,6 @@ gf框架基于模块化设计,实现了通用的HTTP/TCP/UDP Server,并实
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!--
|
||||
## 配置
|
||||
1. 默认读取文件运行目录的config.json文件;
|
||||
1. 支持多配置文件管理,默认配置文件目录为当前运行目录;
|
||||
@ -136,6 +124,16 @@ gf框架基于模块化设计,实现了通用的HTTP/TCP/UDP Server,并实
|
||||
```json
|
||||
{
|
||||
"viewpath" : "视图文件存放路径",
|
||||
"routings" : {
|
||||
"dispatch" : {
|
||||
"解析匹配规则1" : "解析替换规则1",
|
||||
"解析匹配规则2" : "解析替换规则2"
|
||||
},
|
||||
"patch" : {
|
||||
"打包匹配规则1" : "打包替换规则1",
|
||||
"打包匹配规则2" : "打包替换规则2"
|
||||
}
|
||||
},
|
||||
"database" : {
|
||||
"数据库分组名称" : [
|
||||
{
|
||||
@ -156,7 +154,12 @@ gf框架基于模块化设计,实现了通用的HTTP/TCP/UDP Server,并实
|
||||
1. config.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" : {
|
||||
"default" : [
|
||||
{
|
||||
@ -198,4 +201,4 @@ gf框架基于模块化设计,实现了通用的HTTP/TCP/UDP Server,并实
|
||||
}
|
||||
}
|
||||
```
|
||||
-->
|
||||
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"gitee.com/johng/gf/g/container/gmap"
|
||||
"gitee.com/johng/gf/g/encoding/gjson"
|
||||
"sync"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -48,7 +49,10 @@ func (c *Config) filePath(files []string) string {
|
||||
// 设置配置管理器的配置文件存放目录绝对路径
|
||||
func (c *Config) SetPath(path string) {
|
||||
c.mu.Lock()
|
||||
if strings.Compare(c.path, path) != 0 {
|
||||
c.path = path
|
||||
c.jsons = gmap.NewStringInterfaceMap()
|
||||
}
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
|
9
geg/frame/mvc/controller/demo/config.go
Normal file
9
geg/frame/mvc/controller/demo/config.go
Normal 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")
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user