Skip to content

Latest commit

 

History

History
47 lines (36 loc) · 928 Bytes

README.md

File metadata and controls

47 lines (36 loc) · 928 Bytes

fswatch

Test Lint Go Reference

fswatch is a simple fsnotify wrapper to watch file updates correctly.

Install

go get github.com/sagernet/fswatch

Example

package main

import (
	"log"

	"github.com/sagernet/fswatch"
)

func main() {
	var watchPath []string
	watchPath = append(watchPath, "/tmp/my_file")
	watcher, err := fswatch.NewWatcher(fswatch.Options{
		Path: watchPath,
		Callback: func(path string) {
			log.Println("file updated: ", path)
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	defer watcher.Close()
	// Block main goroutine forever.
	<-make(chan struct{})
}