filewatcher

package
v0.0.0-...-0956853 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Contents []byte // Static contents that never change, for unified handling
	FilePath string
	Interval time.Duration
	OnChange func(contents []byte)
	Logr     logr.Logger
}

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher is file watcher that polls a file for changes in the background. For convenience, it also supports single content loads without a background watcher.

func New

func New(ctx context.Context, opt Options) (*Watcher, error)

New creates and new Watcher and starts the background watch goroutine if needed. The first poll is done immediately and any error there will be immediately returned and not further polling done in this case. The OnChange callback is not called for this first poll. The background goroutine can be cancelled through the passed context.

func (*Watcher) Contents

func (w *Watcher) Contents() []byte

Contents returns the current file contents

func (*Watcher) Err

func (w *Watcher) Err() error

Err returns the last error encountered when polling.

Jump to

Keyboard shortcuts

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