watch

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2025 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Copyright (c) 2023-2025 Chakib Ben Ziane <contact@blob42.xyz> and [`GoSuki` contributors] (https://github.com/blob42/gosuki/graphs/contributors).

All rights reserved.

SPDX-License-Identifier: AGPL-3.0-or-later

This file is part of GoSuki.

GoSuki is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

GoSuki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with gosuki. If not, see <http://www.gnu.org/licenses/>.

Watch package provides functionality for watching file system events and managing bookmark data sources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReduceEvents

func ReduceEvents(interval time.Duration,
	w WatchRunner)

Run reducer in its own thread when the watcher is started It receives a struct{event, func} and runs the func only once in the interval

func WatchLoop

func WatchLoop(w any)

Main thread for watching file changes

Types

type EventType

type EventType int

type Fetcher

type Fetcher interface {
	Fetch() ([]*gosuki.Bookmark, error)
}

Fetcher is an interface for modules that fetches data from some source and produces a list of bookmarks.

type Loader

type Loader interface {
	Load() ([]*gosuki.Bookmark, error)
}

Loader is an interface for modules that can load bookmarks. It requires the implementation of a Load method, which returns a slice of pointers to gosuki.Bookmark and an error.

type PollWork

type PollWork struct {
	Name string

	Poller
}

Implement work unit for poller runners

func (PollWork) Run

func (iw PollWork) Run(m manager.UnitManager)

type Poller

type Poller interface {
	Fetcher
	Interval() time.Duration
}

Modules that periodically fetch data

type ResetWatcher

type ResetWatcher interface {
	ResetWatcher() error // resets a new watcher
}

If the browser needs the watcher to be reset for each new event

type Runner

type Runner interface {
	Run()
}

Modules the implement their bookmark loading through a Run() method with an internal logic of handling bookmarks and direct sync with gosuki DB Mostly used through implementing WatchRunner

type Shutdowner

type Shutdowner interface {
	Shutdown() error
}

type StatMaker

type StatMaker interface {
	ResetStats()
}

StatMaker interface can be implemented in modules that keep and track stats

type Watch

type Watch struct {
	Path       string        // Path to watch for events
	EventTypes []fsnotify.Op // events to watch for

	// event names to watch for (file/dir names)
	// use "*" to watch all names
	EventNames []string

	// Reset the watcher at each event occurence (useful for `create` events)
	ResetWatch bool
}

Watch is a filesystem object that can be watched for changes.

type WatchDescriptor

type WatchDescriptor struct {
	// ID is a unique identifier for the watch descriptor.
	ID string

	// W is the underlying fsnotify.Watcher that this wrapper uses to monitor file system events.
	W *fsnotify.Watcher

	// Watches is a slice of pointers to Watch objects, which represent specific files or directories being watched.
	Watches []*Watch

	// List of unique event names that where encountered
	// Useful to track unique filenames in a watched path
	TrackEventNames bool
	EventNames      []string
	// contains filtered or unexported fields
}

WatchDescriptor is a warpper around an fsnotify.Watcher that defines watch properties.

func NewWatcher

func NewWatcher(name string, watches ...*Watch) (*WatchDescriptor, error)

func NewWatcherWithReducer

func NewWatcherWithReducer(name string, reducerLen int, watches ...*Watch) (*WatchDescriptor, error)

func (*WatchDescriptor) AddEventName

func (w *WatchDescriptor) AddEventName(name string)

type WatchLoad

type WatchLoad struct {
	WatchLoader
}

A module that needs to watch paths to load boomkarks. Browsers SHOULD use WatchRunner instead.

func (WatchLoad) Run

func (w WatchLoad) Run(m manager.UnitManager)

Implement work unit for watch loaders

type WatchLoader

type WatchLoader interface {
	Watcher
	Loader

	Name() string // module name
}

WatchLoader is an interface that combines the capabilities of both Watcher and Loader interfaces. It is intended for modules that need to watch for changes and also load bookmarks through the Load method.

type WatchRunner

type WatchRunner interface {
	Watcher
	Runner
}

type WatchWork

type WatchWork struct {
	WatchRunner
}

Implement work unit for watchers

func WatchWorkers

func WatchWorkers(m *manager.Manager) []*WatchWork

func (WatchWork) Run

func (w WatchWork) Run(m manager.UnitManager)

type Watcher

type Watcher interface {
	Watch() *WatchDescriptor
}

Required interface to be implemented by browsers that want to use the fsnotify event loop and watch changes on bookmark files.

Jump to

Keyboard shortcuts

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