v0.3.11 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2016 License: BSD-3-Clause, MIT Imports: 10 Imported by: 0


File system notifications for Go

Coverage GoDoc

Go 1.3+ required.

Cross platform: Windows, Linux, BSD and OS X.

Adapter OS Status
inotify Linux, Android* Supported Build Status
kqueue BSD, OS X, iOS* Supported Circle CI
ReadDirectoryChangesW Windows Supported Build status
FSEvents OS X Planned
FEN Solaris 11 Planned
fanotify Linux 2.6.37+
USN Journals Windows Maybe
Polling All Maybe

* Android and iOS are untested.

Please see the documentation for usage. Consult the Wiki for the FAQ and further information.

API stability

Two major versions of fsnotify exist.

fsnotify.v0 is API-compatible with howeyc/fsnotify. Bugfixes may be backported, but I recommend upgrading to v1.

import "gopkg.in/fsnotify.v0"

* Refer to the package as fsnotify (without the .v0 suffix).

fsnotify.v1 provides a new API based on this design document. You can import v1 with:

import "gopkg.in/fsnotify.v1"

Further API changes are planned, but a new major revision will be tagged, so you can depend on the v1 API.

Master may have unreleased changes. Use it to test the very latest code or when contributing, but don't expect it to remain API-compatible:

import "github.com/go-fsnotify/fsnotify"


Please refer to CONTRIBUTING before opening an issue or pull request.


See example_test.go.



Package fsnotify provides a platform-independent interface for file system notifications.




This section is empty.


This section is empty.


This section is empty.


type Event

type Event struct {
	Name string // Relative path to the file or directory.
	Op   Op     // File operation that triggered the event.

Event represents a single file system notification.

func (Event) String

func (e Event) String() string

String returns a string representation of the event in the form "file: REMOVE|WRITE|..."

type Op

type Op uint32

Op describes a set of file operations.

const (
	Create Op = 1 << iota

These are the generalized file operations that can trigger a notification.

type Watcher

type Watcher struct {
	Events chan Event
	Errors chan error
	// contains filtered or unexported fields

Watcher watches a set of files, delivering events to a channel.

func NewWatcher

func NewWatcher() (*Watcher, error)

NewWatcher establishes a new watcher with the underlying OS and begins waiting for events.

package main

import (


func main() {
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
	defer watcher.Close()

	done := make(chan bool)
	go func() {
		for {
			select {
			case event := <-watcher.Events:
				log.Println("event:", event)
				if event.Op&fsnotify.Write == fsnotify.Write {
					log.Println("modified file:", event.Name)
			case err := <-watcher.Errors:
				log.Println("error:", err)

	err = watcher.Add("/tmp/foo")
	if err != nil {

func (*Watcher) Add

func (w *Watcher) Add(name string) error

Add starts watching the named file or directory (non-recursively).

func (*Watcher) Close

func (w *Watcher) Close() error

Close removes all watches and closes the events channel.

func (*Watcher) Remove

func (w *Watcher) Remove(name string) error

Remove stops watching the named file or directory (non-recursively).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL