Skip to content

Installation

  • Go 1.26 or later
  • An active Go module (go.mod)

Run this in your project directory:

Terminal window
go get github.com/larsartmann/go-filewatcher/v2@latest
package main
import (
"context"
"fmt"
"log"
"time"
filewatcher "github.com/larsartmann/go-filewatcher/v2"
)
func main() {
watcher, err := filewatcher.New(
[]string{"./src"},
filewatcher.WithExtensions(".go"),
filewatcher.WithDebounce(500*time.Millisecond),
)
if err != nil {
log.Fatal(err)
}
defer watcher.Close()
events, err := watcher.Watch(context.Background())
if err != nil {
log.Fatal(err)
}
for event := range events {
fmt.Printf("%s: %s\n", event.Op, event.Path)
}
}
Terminal window
go list -m github.com/larsartmann/go-filewatcher/v2
  • Follow the Quick Start for complete examples
  • Learn about Filtering to control which events you receive
  • Explore Middleware for cross-cutting concerns