github.com/gogf/gf@v1.16.9/.example/os/gcfg/basic/gcfg_auto_update.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/gogf/gf/os/gtimer"
     8  
     9  	"github.com/gogf/gf/frame/g"
    10  )
    11  
    12  // 配置文件热更新示例
    13  func main() {
    14  	c := g.Config()
    15  	// 每隔1秒打印当前配置项值,用户可手动在外部修改文件内容,gcfg读取到的配置项值会即时得到更新
    16  	gtimer.SetInterval(time.Second, func() {
    17  		fmt.Println(c.Get("viewpath"))
    18  	})
    19  
    20  	select {}
    21  }