watcher

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 13 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Watcher

Go Reference

Resilient file watcher. Used in Bud.

Features

  • Watches a directory recursively
  • Debounces multiple events into a single function call
  • Smooths over differences between operating systems
  • Ignores files in your .gitignore
  • Generally does what you'd expect

Install

go get -u github.com/livebud/watcher

Example

package main

import (
  "context"
  "fmt"
  "os"

  "github.com/livebud/watcher"
)

func main() {
  ctx := context.Background()
  if err := run(ctx); err != nil {
    fmt.Fprintln(os.Stderr, err)
    os.Exit(1)
  }
}

func run(ctx context.Context) error {
  return watcher.Watch(ctx, ".", func(events []watcher.Event) error {
    for _, event := range events {
      fmt.Println(string(event.Op), event.Path)
    }
    return nil
  })
}

Contributing

Thank you for your interest in contributing! To get started, first clone the repo:

git clone https://github.com/livebud/watcher
cd watcher

Next, install the dependencies:

go mod tidy

Finally, try running the tests:

go test ./...

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Stop = errors.New("stop watching")

Stop informs the watcher to stop.

Functions

func Watch

func Watch(ctx context.Context, dir string, fn func(events []Event) error) error

Watch a directory of files

Types

type Event

type Event struct {
	Op   Op
	Path string
}

Event is used to track file events

func (Event) String

func (e Event) String() string

type Op

type Op string

Op is the type of file event that occurred

const (
	OpCreate Op = "create"
	OpUpdate Op = "update"
	OpDelete Op = "delete"
)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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