locafero

package module
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 7 Imported by: 12 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Finder library for Afero

GitHub Workflow Status go.dev reference GitHub go.mod Go version OpenSSF Scorecard

Finder library for Afero ported from go-finder.

[!WARNING] This is an experimental library under development.

Backwards compatibility is not guaranteed, expect breaking changes.

Installation

go get github.com/sagikazarmark/locafero

Usage

Check out the package example on go.dev.

Development

For an optimal developer experience, it is recommended to install Nix and direnv.

Run the test suite:

just test

License

The project is licensed under the MIT License.

Documentation

Overview

Package locafero looks for files and directories in an {fs.Fs} filesystem.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NameWithExtensions

func NameWithExtensions(baseName string, extensions ...string) []string

NameWithExtensions creates a list of names from a base name and a list of extensions.

TODO: find a better name for this function.

func NameWithOptionalExtensions

func NameWithOptionalExtensions(baseName string, extensions ...string) []string

NameWithOptionalExtensions creates a list of names from a base name and a list of extensions, plus it adds the base name (without any extensions) to the end of the list.

TODO: find a better name for this function.

Types

type FileType

type FileType int

FileType represents the kind of entries Finder can return.

const (
	FileTypeAny FileType = iota
	FileTypeFile
	FileTypeDir

	// Deprecated: Use [FileTypeAny] instead.
	FileTypeAll = FileTypeAny
)

FileType represents the kind of entries Finder can return.

type Finder

type Finder struct {
	// Paths represents a list of locations that the [Finder] will search in.
	//
	// They are essentially the root directories or starting points for the search.
	//
	// Examples:
	//   - home/user
	//   - etc
	Paths []string

	// Names are specific entries that the [Finder] will look for within the given Paths.
	//
	// It provides the capability to search for entries with depth,
	// meaning it can target deeper locations within the directory structure.
	//
	// It also supports glob syntax (as defined by [filepath.Match]), offering greater flexibility in search patterns.
	//
	// Examples:
	//   - config.yaml
	//   - home/*/config.yaml
	//   - home/*/config.*
	Names []string

	// Type restricts the kind of entries returned by the [Finder].
	//
	// This parameter helps in differentiating and filtering out files from directories or vice versa.
	Type FileType
}

Finder looks for files and directories in an afero.Fs filesystem.

func (Finder) Find

func (f Finder) Find(fsys afero.Fs) ([]string, error)

Find looks for files and directories in an afero.Fs filesystem.

Example
fsys := afero.NewBasePathFs(afero.NewOsFs(), "testdata")

finder := Finder{
	Paths: []string{
		"/home/user",
		"/etc",
	},
	Names: []string{"config.*"},
	Type:  FileTypeFile,
}

results, err := finder.Find(fsys)
if err != nil {
	panic(err)
}

fmt.Println("On Unix:", results)
Output:
On Unix: [/home/user/config.yaml /etc/config.yaml]

Directories

Path Synopsis
internal
queue
Package queue provides a generic queue implementation.
Package queue provides a generic queue implementation.

Jump to

Keyboard shortcuts

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