diff --git a/g/os/gcfg/gcfg.go b/g/os/gcfg/gcfg.go index 622cfcf98..256e2b038 100644 --- a/g/os/gcfg/gcfg.go +++ b/g/os/gcfg/gcfg.go @@ -9,6 +9,7 @@ package gcfg import ( + "gitee.com/johng/gf/g/container/gvar" "gitee.com/johng/gf/g/os/gspath" "gitee.com/johng/gf/g/os/gfsnotify" "gitee.com/johng/gf/g/container/gmap" @@ -120,6 +121,14 @@ func (c *Config) Get(pattern string, file...string) interface{} { return nil } +// 获得配置项,返回动态变量 +func (c *Config) GetVar(pattern string, file...string) *gvar.Var { + if j := c.getJson(file...); j != nil { + return gvar.New(j.Get(pattern)) + } + return nil +} + // 获得一个键值对关联数组/哈希表,方便操作,不需要自己做类型转换 // 注意,如果获取的值不存在,或者类型与json类型不匹配,那么将会返回nil func (c *Config) GetMap(pattern string, file...string) map[string]interface{} { diff --git a/g/os/gfsnotify/gfsnotify.go b/g/os/gfsnotify/gfsnotify.go index 44bb1923f..8c0263ccf 100644 --- a/g/os/gfsnotify/gfsnotify.go +++ b/g/os/gfsnotify/gfsnotify.go @@ -163,7 +163,7 @@ func (w *Watcher) startWatchLoop() { // 监听事件 case ev := <- w.watcher.Events: - //glog.Debug("gfsnotify:", ev) + //glog.Debug("gfsnotify: watch loop", ev) w.events.Push(&Event{ Path : ev.Name, Op : Op(ev.Op), @@ -193,18 +193,21 @@ func (w *Watcher) startEventLoop() { go func() { for { if v := w.events.Pop(); v != nil { + //glog.Debug("gfsnotidy: event loop", v) event := v.(*Event) if event.IsRemove() { if gfile.Exists(event.Path) { // 如果是文件删除事件,判断该文件是否存在,如果存在,那么将此事件认为“假删除”, // 并重新添加监控(底层fsnotify会自动删除掉监控,这里重新添加回去) w.watcher.Add(event.Path) - continue + // 修改时间操作为写入 + event.Op = WRITE } else { // 如果是真实删除,那么递归删除监控信息 w.Remove(event.Path) } } + //glog.Debug("gfsnotidy: event loop callbacks", v) callbacks := w.getCallbacks(event.Path) // 如果创建了新的目录,那么将这个目录递归添加到监控中 if event.IsCreate() && gfile.IsDir(event.Path) { diff --git a/geg/os/gcfg/gcfg3.go b/geg/os/gcfg/gcfg3.go index a6b690f34..6b8522504 100644 --- a/geg/os/gcfg/gcfg3.go +++ b/geg/os/gcfg/gcfg3.go @@ -6,6 +6,6 @@ import ( ) func main() { - fmt.Println(g.Config().Get("serverpath")) + fmt.Println(g.Config().GetVar("memcache.0").String()) }