Files
gf/.example/os/gcfg/basic/gcfg_auto_update.go

22 lines
396 B
Go
Raw Normal View History

package main
import (
2019-04-03 00:03:46 +08:00
"fmt"
"time"
2019-07-29 21:01:19 +08:00
2019-08-19 21:02:44 +08:00
"github.com/gogf/gf/os/gtimer"
2019-07-29 21:01:19 +08:00
"github.com/gogf/gf/frame/g"
)
// 配置文件热更新示例
func main() {
2019-04-03 00:03:46 +08:00
c := g.Config()
// 每隔1秒打印当前配置项值用户可手动在外部修改文件内容gcfg读取到的配置项值会即时得到更新
2019-08-19 21:02:44 +08:00
gtimer.SetInterval(time.Second, func() {
2019-04-03 00:03:46 +08:00
fmt.Println(c.Get("viewpath"))
})
2019-04-03 00:03:46 +08:00
select {}
}