package
0.8.3
Repository: https://github.com/lalamove/konfig.git
Documentation: pkg.go.dev

# README

File Watcher

File Watcher watches over a file given in the config.

Usage

import (
	"fmt"
	"io/ioutil"
	"os"
	"time"

	"github.com/lalamove/konfig/watcher/kwfile"
)

func main() {
	f, _ := ioutil.TempFile("", "konfig")
	f.Write([]byte(`ABC`))

	defer os.Remove(f.Name())

	var n = kwfile.New(&kwfile.Config{
		Files: []string{f.Name()},
		Rate:  100 * time.Millisecond,
		Debug: true,
	})

	n.Start()

	time.Sleep(100 * time.Millisecond)

	f.Write([]byte(`12345`))

	var timer = time.NewTimer(200 * time.Millisecond)
	select {
	case now := <-timer.C:
		fmt.Println(now)
		break
	case <-n.Done():
		fmt.Println("done!")
		break
	case <-n.Watch():
		fmt.Println("file changed!") // will see this log
		break
	}
}

# Functions

New creates a new FileWatcher from the given *Config cfg.

# Structs

Config is the config of a FileWatcher.
FileWatcher watches over a file given in the config.