watchandqueue

package module
v0.0.0-...-2ec3a91 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

watchandqueue

Watch for files being written and queue them when they are ready.

When a file is written in the folder of your choosing, a string containing the filename will be sent on a channel.

// The channel 'c' will receive the full filenames of the files that have been written. 

	ctx := context.Background()
	c := make(chan string, 5)
	go func() {
		for {
			file := <-c
			fmt.Println("Got:", file)
		}
	}()
	fmt.Println("Starting file watcher")
	err := WatchForIncomingFiles(ctx, "/tmp", ".log", c)
	if err != nil {
		log.Println(err)
	}

This was cobbled together really quickly to solve a problem I had. It works and does the job it has to do for me. YMMV. Improvements are definitely possible and are encouraged, but for me personally this is fine the way it is now.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Verbose = false
)

Functions

func SetPollInterval

func SetPollInterval(interval int)

func WatchForIncomingFiles

func WatchForIncomingFiles(ctx context.Context, watchDirectory, extension string, c chan<- string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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