file

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Watch

func Watch(filename string, callback func()) error

Watch watches the given filename and calls the given callback when the file is changed. The watcher uses the parent directory as a watchpoint to be notified if the file doesn't exist when the watcher is created. When the file is a symlink (like a ConfigMap or a Secret mounted in a Kubernetes Pod), a change of its target is detected as well. It relies on the events of the parent directory, which are all reported by inotify on Linux, but not always by kqueue (macOS, BSD). The file is watched until the end of the process. Use WatchWithContext to stop watching it. Example:

	file.Watch("/tmp/test.txt", func() {
		fmt.Println("File created or changed")
	}
)

func WatchWithContext added in v0.32.0

func WatchWithContext(ctx context.Context, filename string, callback func()) error

WatchWithContext is like Watch, but it stops watching the file once the context is done. The callback is not called anymore once the context is done, but a call in progress is not waited for.

Types

This section is empty.

Jump to

Keyboard shortcuts

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