Beispiel #1
0
func main() {
	flag.Parse()

	// Write our first entry
	if err := writeFile(0); err != nil {
		fmt.Println(err)
		return
	}
	defer os.Remove(configFile)

	// Create a config instance
	config := config.NewConfig(
		// aggressive config polling
		config.PollInterval(time.Millisecond*500),
		// use file as a config source
		config.WithSource(file.NewSource(config.SourceName(configFile))),
	)

	fmt.Println("Starting config runner")

	// Start the config runner which polls config
	config.Start()

	// lets read the value while editing it a number of times
	for i := 0; i < 10; i++ {
		val := config.Get("key").String("default")
		fmt.Println("Got ", val)
		writeFile(i + 1)
		time.Sleep(time.Second)
	}

	fmt.Println("Stopping config runner")

	// Stop the runner. The cache is still populated
	config.Stop()
}
Beispiel #2
0
func main() {
	flag.Parse()

	// Write our first entry
	if err := writeFile(0); err != nil {
		fmt.Println(err)
		return
	}
	defer os.Remove(configFile)

	// Create a config instance
	config := config.NewConfig(
		// aggressive config polling
		config.PollInterval(time.Millisecond*500),
		// use file as a config source
		config.WithSource(file.NewSource(config.SourceName(configFile))),
	)

	defer config.Close()

	// lets read the value while editing it a number of times
	for i := 0; i < 10; i++ {
		val := config.Get("key").String("default")
		fmt.Println("Got ", val)
		writeFile(i + 1)
		time.Sleep(time.Second)
	}

	// watch key that exists
	watch(config, "key")

	// watch key that does not exist
	watch(config, "foo")

	fmt.Println("Stopping config runner")
}