gomon

package module
v0.0.0-...-b1b9002 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: MIT Imports: 9 Imported by: 0

README ΒΆ

Gomon

You can capture file or folder changes, but that's not all.

Gomon saves the last modification dates of the watched files, so it can detect any changes when it is started at a later time.

🎯 Future

  • Errors.
  • Save the files under the directory.

⚑️ Quickstart

package main

import (
  "log"

  "github.com/ichbinbekir/gomon"
)

func main() {
  watcher, err := gomon.NewWatcher(Config{Save: "dates.json"})
  if err != nil {
    log.Fatal(err)
  }
  defer watcher.Close()

  if _, err := watcher.Add("test.txt"); err != nil {
    log.Fatal(err)
  }

  for {
    select {
    case event, ok := <-watcher.Events:
      if !ok {
        break
      }
      // Print file modifications
      log.Println(event)
    case err := <-watcher.Errors:
      log.Fatal(err)
    }
  }
}

βš™οΈ Installation

go get -u github.com/ichbinbekir/gomon

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type Config ΒΆ

type Config struct {
	// Events and Errors channel buffer size, both fsnotify and gomon.
	BufferSize uint

	// Save files or directories modification dates to file.
	Save string
}

type Event ΒΆ

type Event struct {
	Name string
	Op   Op
}

func (Event) Has ΒΆ

func (e Event) Has(op Op) bool

func (Event) String ΒΆ

func (e Event) String() string

type Op ΒΆ

type Op fsnotify.Op
const (
	// Default fsnotify
	Create Op = 1 << iota
	Write
	Remove
	Rename
	Chmod

	// Special for gomon
	Non Op = 0
)

func (Op) Has ΒΆ

func (o Op) Has(h Op) bool

func (Op) String ΒΆ

func (o Op) String() string

type SaveError ΒΆ

type SaveError struct {
	Op  string // truncate, seek, encode, vb.
	Err error
}

func (*SaveError) Error ΒΆ

func (e *SaveError) Error() string

func (*SaveError) Unwrap ΒΆ

func (e *SaveError) Unwrap() error

type Watcher ΒΆ

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

func NewWatcher ΒΆ

func NewWatcher(configs ...Config) (*Watcher, error)

func (*Watcher) Add ΒΆ

func (w *Watcher) Add(path string) (Op, error)

func (*Watcher) Close ΒΆ

func (w *Watcher) Close() error

func (*Watcher) Config ΒΆ

func (w *Watcher) Config() Config

Jump to

Keyboard shortcuts

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