func New() (*Watcher, error) {
	w := &Watcher{}
	w.t = time.Millisecond * 500
	w.Event = make(chan *Event)
	w.watching = true
	w.Files = make(map[string]*WatcherFile)
	go func() {
		for w.watching {
			w.check()
			time.Sleep(w.t)
		}
	}()
	return w, nil
}
New allocates, returns a file watcher and starts the watching loop.
package watcher
import (
	"os"
	"time"
)
type Event struct {
	Name string
	isModify bool
}
type Watcher struct {
	Files    map[string]*WatcherFile
	Event    chan (*Event)
	t        time.Duration
	watching bool
}
type WatcherFile struct {
	Filemtime time.Time
}
func (ev *Event) IsModify() bool {
	if ev.isModify == true {
		ev.isModify = false
		return true
	}
	return false
}
func (w *Watcher) RemoveWatch(file string) error {
	delete(w.Files, file)
	return nil
}
func (w *Watcher) Watch(file string) error {
	stat, err := os.Stat(file)
	if err != nil {
		return err
	}
	wf := &WatcherFile{
		Filemtime: stat.ModTime(),
	}
	w.Files[file] = wf
	return nil
}
func (w *Watcher) check() {
	for name, f := range w.Files {
		stat, err := os.Stat(name)
		if err == nil {
			mtime := stat.ModTime()
			if mtime != f.Filemtime {
				ev := &Event{
					Name:     name,
					isModify: true,
				}
				f.Filemtime = mtime
				w.Event <- ev
			}
		}
	}
}
func (w *Watcher) Close() {
	w.watching = false
}