file

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DecoderErr

type DecoderErr struct {
	Err     error
	Path    string
	Decoder dials.Decoder
}

DecoderErr wraps another error returned by the inner decoder

func (*DecoderErr) Error

func (d *DecoderErr) Error() string

func (*DecoderErr) Unwrap

func (d *DecoderErr) Unwrap() error

type Source

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

Source is a raw file source. Errors reported by the wrapped decoder will be reported wrapped in a DecoderErr with the error and file-path populated.

func NewSource

func NewSource(path string, decoder dials.Decoder) (*Source, error)

NewSource converts path to an absolute path and returns a source for that file.

func (*Source) Value

func (s *Source) Value(_ context.Context, t *dials.Type) (reflect.Value, error)

Value opens the file and passes it to the Decoder.

type StdLogger

type StdLogger interface {
	Printf(string, ...interface{})
	Print(...interface{})
}

StdLogger is an interface satisified by several logging types, including the stdlib `log.Logger`, and `github.com/rs/zerolog.Logger`, and should be trivial enough to wrap in other cases.

type WatchOpt

type WatchOpt func(*WatchOpts)

WatchOpt functions mutate the state of a WatchOpts, providing optional arguments to NewWatchingSource

func WithLogger

func WithLogger(logger StdLogger) WatchOpt

WithLogger sets a logger on the new WatchingSource.

func WithPollInterval

func WithPollInterval(pollInterval time.Duration) WatchOpt

WithPollInterval configures the new WatchingSource to use a fallback ticker to trigger polling for changes to files.

func WithSignalChannel

func WithSignalChannel(sigCh chan os.Signal) WatchOpt

WithSignalChannel configures the new WatchingSource to use the provided channel as a manual trigger for rereading the config file (useful with SIGHUP).

type WatchOpts

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

WatchOpts contains options, which can be mutated by a WatchOpt

type WatchingSource

type WatchingSource struct {
	Source
	Reload       chan os.Signal
	PollInterval time.Duration
	WG           sync.WaitGroup
	// contains filtered or unexported fields
}

WatchingSource uses fsnotify (inotify, dtrace, etc) to watch for changes to a file Errors reported by the wrapped decoder will be reported wrapped in a DecoderErr with the error and file-path populated.

func NewWatchingSource

func NewWatchingSource(
	path string,
	decoder dials.Decoder,
	opts ...WatchOpt,
) (*WatchingSource, error)

NewWatchingSource creates a new file watching source that will reload and notify if the file is updated.

func (*WatchingSource) Watch

func (ws *WatchingSource) Watch(
	ctx context.Context,
	t *dials.Type,
	args dials.WatchArgs) error

Watch Sets up an fsnotify Watcher and starts a background goroutine for watching changes.

Jump to

Keyboard shortcuts

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