walker

package
v0.0.0-...-c3373f0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2024 License: Apache-2.0, MIT Imports: 10 Imported by: 5

Documentation

Overview

Package walker provides implementations for walking over files in a filesystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FSReverseWalker

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

FSReverseWalker is a ReverseWalker that walks over the local filesystem.

func NewCustomReverseFSWalker

func NewCustomReverseFSWalker(fs afero.Fs, logger *slog.Logger) FSReverseWalker

NewCustomReverseFSWalker creates a new FSReverseWalker with the given filesystem and an optional logger.

func NewDefaultFSReverseWalker

func NewDefaultFSReverseWalker(logger *slog.Logger) FSReverseWalker

NewFSReverseWalker creates a new FSReverseWalker with default settings and an optional logger.

func NewFSReverseWalker

func NewFSReverseWalker(logger *slog.Logger, fs afero.Fs) FSReverseWalker

NewFSReverseWalker creates a new FSReverseWalker with an optional logger.

func (*FSReverseWalker) Walk

func (w *FSReverseWalker) Walk(startPath, endPath string, callback WalkerCallback) error

Walk performs a reverse walk over the files and directories from the start path to the end path and calls the given function for each entry.

type FSWalker

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

FilesystemWalker is a walker that walks over the local filesystem.

func NewCustomDefaultFSWalker

func NewCustomDefaultFSWalker(fs afero.Fs, logger *slog.Logger) FSWalker

NewCustomDefaultFilesystemWalker creates a new FSWalker with the given filesystem and an optional logger.

func NewDefaultFSWalker

func NewDefaultFSWalker(logger *slog.Logger) FSWalker

NewDefaultFilesystemWalker creates a new FSWalker with the default filesystem and an optional logger.

func NewFSWalker

func NewFSWalker(fs afero.Fs, logger *slog.Logger) FSWalker

NewFilesystemWalker creates a new FSWalker with the given filesystem.

func (*FSWalker) Walk

func (w *FSWalker) Walk(rootPath string, callback WalkerCallback) error

Walk walks over the files and directories in the given root path and calls the given function for each entry. The reader passed to the function is closed after the function returns.

type FileSeeker

type FileSeeker interface {
	fs.File
	io.Seeker
}

FileSeeker is an interface that combines the fs.File and io.Seeker interfaces.

type FileType

type FileType int

FileType is an enum that represents the type of a file.

const (
	// FileTypeFile represents a file.
	FileTypeFile FileType = iota

	// FileTypeDir represents a directory.
	FileTypeDir
)

type ReverseWalker

type ReverseWalker interface {
	// Walk performs a reverse walk from the end path to the start path and
	// calls the given function for each file.
	Walk(startPath, endPath string, callback WalkerCallback) error
}

ReverseWalker is an interface that allows reverse walking over a set of files. The start path is the path where the walk starts and the end path is the path where the walk ends.

type ReverseWalkerMock

type ReverseWalkerMock struct {
	// WalkFunc mocks the Walk method.
	WalkFunc func(startPath string, endPath string, callback WalkerCallback) error
	// contains filtered or unexported fields
}

ReverseWalkerMock is a mock implementation of ReverseWalker.

func TestSomethingThatUsesReverseWalker(t *testing.T) {

	// make and configure a mocked ReverseWalker
	mockedReverseWalker := &ReverseWalkerMock{
		WalkFunc: func(startPath string, endPath string, callback WalkerCallback) error {
			panic("mock out the Walk method")
		},
	}

	// use mockedReverseWalker in code that requires ReverseWalker
	// and then make assertions.

}

func (*ReverseWalkerMock) Walk

func (mock *ReverseWalkerMock) Walk(startPath string, endPath string, callback WalkerCallback) error

Walk calls WalkFunc.

func (*ReverseWalkerMock) WalkCalls

func (mock *ReverseWalkerMock) WalkCalls() []struct {
	StartPath string
	EndPath   string
	Callback  WalkerCallback
}

WalkCalls gets all the calls that were made to Walk. Check the length with:

len(mockedReverseWalker.WalkCalls())

type Walker

type Walker interface {
	// Walk walks over the files in the given root path and calls the given
	// function for each file.
	Walk(rootPath string, callback WalkerCallback) error
}

Walker is an interface that allows walking over a set of files.

type WalkerCallback

type WalkerCallback func(string, FileType, func() (FileSeeker, error)) error

WalkerCallback is a callback function that is called for each file in the Walk function.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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