finder

package
v0.6.15 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 14 Imported by: 1

README

finder

GoDoc

finder Provides a simple and convenient filedir lookup function, supports filtering, excluding, matching, ignoring, etc. and with some commonly built-in matchers.

Usage

package main

import (
	"github.com/gookit/goutil/dump"
	"github.com/goutil/fsutil/finder"
)

func main() {
	ff := finder.NewFinder()
	ff.AddScan("/tmp", "/usr/local", "/usr/local/share")
	ff.ExcludeDir("abc", "def").ExcludeFile("*.log", "*.tmp")

	ss := ff.FindPaths()
	dump.P(ss)
}

Built-in Matchers

func FileSize(min, max uint64) MatcherFunc
func GlobMatch(patterns ...string) MatcherFunc
func GlobMatches(patterns []string) MatcherFunc
func HumanModTime(expr string) MatcherFunc
func HumanSize(expr string) MatcherFunc
func MatchDotDir() MatcherFunc
func MatchDotFile() MatcherFunc
func MatchExt(exts ...string) MatcherFunc
func MatchExts(exts []string) MatcherFunc
func MatchModTime(start, end time.Time) MatcherFunc
func MatchMtime(start, end time.Time) MatcherFunc
func MatchName(names ...string) MatcherFunc
func MatchNames(names []string) MatcherFunc
func MatchPath(subPaths []string) MatcherFunc
func MatchPaths(subPaths []string) MatcherFunc
func MatchPrefix(prefixes ...string) MatcherFunc
func MatchPrefixes(prefixes []string) MatcherFunc
func MatchSuffix(suffixes ...string) MatcherFunc
func MatchSuffixes(suffixes []string) MatcherFunc
func NameLike(patterns ...string) MatcherFunc
func NameLikes(patterns []string) MatcherFunc
func RegexMatch(pattern string) MatcherFunc
func SizeRange(min, max uint64) MatcherFunc
func StartWithDot() MatcherFunc

Documentation

Overview

Package finder Provides a simple and convenient filedir lookup function, supports filtering, excluding, matching, ignoring, etc. and with some commonly built-in matchers.

Index

Constants

This section is empty.

Variables

View Source
var (
	CommonlyDotDirs  = []string{".git", ".idea", ".vscode", ".svn", ".hg"}
	CommonlyDotFiles = []string{".gitignore", ".dockerignore", ".npmignore", ".DS_Store", ".env"}
)

commonly dot file and dirs

View Source
var MatchDir = MatcherFunc(func(el Elem) bool {
	return el.IsDir()
})

MatchDir only allow dir path.

View Source
var MatchFile = MatcherFunc(func(el Elem) bool {
	return !el.IsDir()
})

MatchFile only allow file path.

Functions

This section is empty.

Types

type BodyMatcher added in v0.6.10

type BodyMatcher interface {
	Apply(filePath string, body *bytes.Buffer) bool
}

BodyMatcher for match file contents.

type BodyMatcherFunc added in v0.6.9

type BodyMatcherFunc func(filePath string, body *bytes.Buffer) bool

BodyMatcherFunc for match file contents.

func (BodyMatcherFunc) Apply added in v0.6.9

func (fn BodyMatcherFunc) Apply(filePath string, body *bytes.Buffer) bool

Apply for match file contents.

type BodyMatchers added in v0.6.10

type BodyMatchers struct {
	Matchers []BodyMatcher
}

BodyMatchers multi body matchers as Matcher

func NewBodyMatchers added in v0.6.10

func NewBodyMatchers(fls ...BodyMatcher) *BodyMatchers

NewBodyMatchers create a new body matchers

Usage:

	bf := finder.NewBodyMatchers(
		finder.BodyMatcherFunc(func(filePath string, buf *bytes.Buffer) bool {
			// match file contents
			return true
		}),
	)

 es := finder.NewFinder('path/to/dir').Add(bf).Elems()
 for el := range es {
		fmt.Println(el.Path())
 }

func (*BodyMatchers) AddMatcher added in v0.6.10

func (mf *BodyMatchers) AddMatcher(fls ...BodyMatcher)

AddMatcher add matchers

func (*BodyMatchers) Apply added in v0.6.10

func (mf *BodyMatchers) Apply(el Elem) bool

Apply check file contents is match.

type Config added in v0.6.9

type Config struct {

	// ScanDirs scan dir paths for find.
	ScanDirs []string `json:"scan_dirs"`
	// FindFlags for find result. default is FlagFile
	FindFlags FindFlag `json:"find_flags"`
	// MaxDepth for find result. default is 0 - not limit
	MaxDepth int `json:"max_depth"`
	// UseAbsPath use abs path for find result. default is false
	UseAbsPath bool `json:"use_abs_path"`
	// CacheResult cache result for find result. default is false
	CacheResult bool `json:"cache_result"`
	// ExcludeDotDir exclude dot dir. default is true
	ExcludeDotDir bool `json:"exclude_dot_dir"`
	// ExcludeDotFile exclude dot dir. default is false
	ExcludeDotFile bool `json:"exclude_dot_file"`

	// Matchers generic include matchers for file/dir elems
	Matchers []Matcher
	// ExMatchers generic exclude matchers for file/dir elems
	ExMatchers []Matcher
	// DirMatchers include matchers for dir elems
	DirMatchers []Matcher
	// DirExMatchers exclude matchers for dir elems
	DirExMatchers []Matcher
	// FileMatchers include matchers for file elems
	FileMatchers []Matcher
	// FileExMatchers exclude matchers for file elems
	FileExMatchers []Matcher

	// IncludeDirs include dir name list. eg: {"model"}
	IncludeDirs []string `json:"include_dirs"`
	// IncludeExts include file ext name list. eg: {".go", ".md"}
	IncludeExts []string `json:"include_exts"`
	// IncludeFiles include file name list. eg: {"go.mod"}
	IncludeFiles []string `json:"include_files"`
	// IncludePaths include file/dir path list. eg: {"path/to"}
	IncludePaths []string `json:"include_paths"`
	// IncludeNames include file/dir name list. eg: {"test", "some.go"}
	IncludeNames []string `json:"include_names"`

	// ExcludeDirs exclude dir name list. eg: {"test"}
	ExcludeDirs []string `json:"exclude_dirs"`
	// ExcludeExts exclude file ext name list. eg: {".go", ".md"}
	ExcludeExts []string `json:"exclude_exts"`
	// ExcludeFiles exclude file name list. eg: {"go.mod"}
	ExcludeFiles []string `json:"exclude_files"`
	// ExcludePaths exclude file/dir path list. eg: {"path/to"}
	ExcludePaths []string `json:"exclude_paths"`
	// ExcludeNames exclude file/dir name list. eg: {"test", "some.go"}
	ExcludeNames []string `json:"exclude_names"`
	// contains filtered or unexported fields
}

Config for finder

func NewConfig added in v0.6.9

func NewConfig(dirs ...string) *Config

NewConfig create a new Config

func NewEmptyConfig added in v0.6.9

func NewEmptyConfig() *Config

NewEmptyConfig create a new Config

func (*Config) Init added in v0.6.9

func (c *Config) Init() *Config

Init build matchers by config and append to Matchers.

func (*Config) LoadRules added in v0.6.13

func (c *Config) LoadRules(addOrNot bool, rules []string) error

LoadRules load rules and parse to config

Rule Format:

NAME:pattern1,pattern2

Examples:

ext:.go,.yaml
name:*_test.go,go.mod

func (*Config) NewFinder added in v0.6.9

func (c *Config) NewFinder() *Finder

NewFinder create a new Finder by config

type Elem added in v0.6.9

type Elem interface {
	fs.DirEntry
	// Path get file/dir full path. eg: "/path/to/file.go"
	Path() string
	// Info get file info. like fs.DirEntry.Info(), but will cache result.
	Info() (fs.FileInfo, error)
}

Elem of find file/dir path result

func NewElem added in v0.6.9

func NewElem(fPath string, ent fs.DirEntry) Elem

NewElem create a new Elem instance

type FileFinder

type FileFinder = Finder

FileFinder type alias.

type FindFlag added in v0.6.9

type FindFlag uint8

FindFlag type for find result.

const (
	FlagFile FindFlag = iota + 1 // only find files(default)
	FlagDir
	FlagBoth = FlagFile | FlagDir
)

flags for find result.

func ToFlag added in v0.6.9

func ToFlag(s string) FindFlag

ToFlag convert string to FindFlag

type Finder added in v0.6.9

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

Finder struct

func EmptyFinder

func EmptyFinder() *Finder

EmptyFinder new empty Finder instance. alias of NewEmpty()

func New added in v0.6.9

func New(dirs []string) *Finder

New instance with source dir paths.

func NewEmpty added in v0.6.9

func NewEmpty() *Finder

NewEmpty new empty Finder instance

func NewFinder

func NewFinder(dirPaths ...string) *Finder

NewFinder new instance with source dir paths.

func NewWithConfig added in v0.6.9

func NewWithConfig(c *Config) *Finder

NewWithConfig new instance with config.

func (*Finder) Add added in v0.6.9

func (f *Finder) Add(fls ...Matcher) *Finder

Add include match matchers. alias of Includes()

func (*Finder) AddFile added in v0.6.9

func (f *Finder) AddFile(fls ...Matcher) *Finder

AddFile add include file matchers

func (*Finder) AddFiles added in v0.6.9

func (f *Finder) AddFiles(fls []Matcher) *Finder

AddFiles add include file matchers

func (*Finder) AddScan added in v0.6.9

func (f *Finder) AddScan(dirPaths ...string) *Finder

AddScan add source dir for find. alias of AddScanDirs()

func (*Finder) AddScanDir added in v0.6.9

func (f *Finder) AddScanDir(dirPaths ...string) *Finder

AddScanDir add source dir for find. alias of AddScanDirs()

func (*Finder) AddScanDirs added in v0.6.9

func (f *Finder) AddScanDirs(dirPaths []string) *Finder

AddScanDirs add source dir for find

func (*Finder) Adds added in v0.6.9

func (f *Finder) Adds(fls []Matcher) *Finder

Adds include match matchers. alias of Includes()

func (*Finder) CacheNum added in v0.6.9

func (f *Finder) CacheNum() int

CacheNum get

func (*Finder) CacheResult added in v0.6.9

func (f *Finder) CacheResult(enable ...bool) *Finder

CacheResult cache result for find result.

func (*Finder) Caches added in v0.6.9

func (f *Finder) Caches() []Elem

Caches get cached results. only valid after finding.

func (*Finder) Collect added in v0.6.9

func (f *Finder) Collect(fls ...Matcher) *Finder

Collect add include match matchers. alias of Includes()

func (*Finder) Config added in v0.6.9

func (f *Finder) Config() Config

Config get

func (*Finder) ConfigFn added in v0.6.9

func (f *Finder) ConfigFn(fns ...func(c *Config)) *Finder

ConfigFn the finder. alias of WithConfigFn()

func (*Finder) Each added in v0.6.9

func (f *Finder) Each(fn func(el Elem))

Each founded file or dir Elem.

func (*Finder) EachContents added in v0.6.9

func (f *Finder) EachContents(fn func(contents, filePath string))

EachContents handle each found file contents

func (*Finder) EachElem added in v0.6.9

func (f *Finder) EachElem(fn func(el Elem))

EachElem founded file or dir Elem.

func (*Finder) EachFile added in v0.6.9

func (f *Finder) EachFile(fn func(file *os.File))

EachFile each file os.File

func (*Finder) EachPath added in v0.6.9

func (f *Finder) EachPath(fn func(filePath string))

EachPath founded file paths.

func (*Finder) EachStat added in v0.6.9

func (f *Finder) EachStat(fn func(fi os.FileInfo, filePath string))

EachStat each file os.FileInfo

func (*Finder) Elems added in v0.6.9

func (f *Finder) Elems() <-chan Elem

Elems find and return founded file Elem. alias of Find()

func (*Finder) Err added in v0.6.9

func (f *Finder) Err() error

Err get last error

func (*Finder) Exclude added in v0.6.9

func (f *Finder) Exclude(fls ...Matcher) *Finder

Exclude add exclude match matchers. alias of Excludes()

func (*Finder) ExcludeDir added in v0.6.9

func (f *Finder) ExcludeDir(dirs ...string) *Finder

ExcludeDir exclude dir names.

func (*Finder) ExcludeDotDir added in v0.6.9

func (f *Finder) ExcludeDotDir(exclude ...bool) *Finder

ExcludeDotDir exclude dot dir names. eg: ".idea"

func (*Finder) ExcludeDotFile added in v0.6.9

func (f *Finder) ExcludeDotFile(exclude ...bool) *Finder

ExcludeDotFile exclude dot dir names. eg: ".gitignore"

func (*Finder) ExcludeExt added in v0.6.9

func (f *Finder) ExcludeExt(exts ...string) *Finder

ExcludeExt exclude file exts.

eg: ExcludeExt(".go", ".java")

func (*Finder) ExcludeFile added in v0.6.9

func (f *Finder) ExcludeFile(files ...string) *Finder

ExcludeFile exclude file names.

func (*Finder) ExcludeName added in v0.6.9

func (f *Finder) ExcludeName(names ...string) *Finder

ExcludeName exclude file names. alias of WithoutNames()

func (*Finder) ExcludePath added in v0.6.9

func (f *Finder) ExcludePath(paths ...string) *Finder

ExcludePath exclude file paths.

func (*Finder) ExcludeRule added in v0.6.13

func (f *Finder) ExcludeRule(rules ...string) *Finder

ExcludeRule exclude rules for finder

func (*Finder) ExcludeRules added in v0.6.13

func (f *Finder) ExcludeRules(rules []string) *Finder

ExcludeRules exclude rules for finder

func (*Finder) Excludes added in v0.6.9

func (f *Finder) Excludes(fls []Matcher) *Finder

Excludes add exclude match matchers

func (*Finder) FileAndDir added in v0.6.9

func (f *Finder) FileAndDir() *Finder

FileAndDir both find file and dir.

func (*Finder) Find added in v0.6.9

func (f *Finder) Find() <-chan Elem

Find files in given dir paths. will return a channel, you can use it to get the result.

Usage:

f := NewFinder("/path/to/dir")
for el := range f.Find() {
	fmt.Println(el.Path())
}

func (*Finder) FindNames added in v0.6.9

func (f *Finder) FindNames() []string

FindNames find and return founded file/dir names.

func (*Finder) FindPaths added in v0.6.9

func (f *Finder) FindPaths() []string

FindPaths find and return founded file/dir paths.

func (*Finder) Include added in v0.6.9

func (f *Finder) Include(fls ...Matcher) *Finder

Include add include match matchers. alias of Includes()

func (*Finder) IncludeDir added in v0.6.9

func (f *Finder) IncludeDir(dirs ...string) *Finder

IncludeDir include dir names.

func (*Finder) IncludeExt added in v0.6.9

func (f *Finder) IncludeExt(exts ...string) *Finder

IncludeExt include file exts.

func (*Finder) IncludeFile added in v0.6.9

func (f *Finder) IncludeFile(files ...string) *Finder

IncludeFile include file names.

func (*Finder) IncludeName added in v0.6.9

func (f *Finder) IncludeName(names ...string) *Finder

IncludeName include file or dir names.

func (*Finder) IncludePath added in v0.6.9

func (f *Finder) IncludePath(paths ...string) *Finder

IncludePath include file or dir paths.

func (*Finder) IncludeRule added in v0.6.13

func (f *Finder) IncludeRule(rules ...string) *Finder

IncludeRule include rules for finder

func (*Finder) IncludeRules added in v0.6.13

func (f *Finder) IncludeRules(rules []string) *Finder

IncludeRules include rules for finder

func (*Finder) Includes added in v0.6.9

func (f *Finder) Includes(fls []Matcher) *Finder

Includes add include match matchers

func (*Finder) MatchDir added in v0.6.9

func (f *Finder) MatchDir(fls ...Matcher) *Finder

MatchDir add exclude dir matchers

func (*Finder) MatchDirs added in v0.6.9

func (f *Finder) MatchDirs(fls []Matcher) *Finder

MatchDirs add exclude dir matchers

func (*Finder) MatchFile added in v0.6.9

func (f *Finder) MatchFile(fls ...Matcher) *Finder

MatchFile add include file matchers

func (*Finder) MatchFiles added in v0.6.9

func (f *Finder) MatchFiles(fls []Matcher) *Finder

MatchFiles add include file matchers

func (*Finder) NoDotDir added in v0.6.9

func (f *Finder) NoDotDir(exclude ...bool) *Finder

NoDotDir exclude dot dir names. alias of ExcludeDotDir().

func (*Finder) NoDotFile added in v0.6.9

func (f *Finder) NoDotFile(exclude ...bool) *Finder

NoDotFile exclude dot dir names. alias of ExcludeDotFile().

func (*Finder) Not added in v0.6.9

func (f *Finder) Not(fls ...Matcher) *Finder

Not add exclude match matchers. alias of Excludes()

func (*Finder) NotDir added in v0.6.9

func (f *Finder) NotDir(fls ...Matcher) *Finder

NotDir add exclude dir matchers

func (*Finder) NotDirs added in v0.6.9

func (f *Finder) NotDirs(fls []Matcher) *Finder

NotDirs add exclude dir matchers

func (*Finder) NotFile added in v0.6.9

func (f *Finder) NotFile(fls ...Matcher) *Finder

NotFile add exclude file matchers

func (*Finder) NotFiles added in v0.6.9

func (f *Finder) NotFiles(fls []Matcher) *Finder

NotFiles add exclude file matchers

func (*Finder) Nots added in v0.6.9

func (f *Finder) Nots(fls []Matcher) *Finder

Nots add exclude match matchers. alias of Excludes()

func (*Finder) Num added in v0.6.9

func (f *Finder) Num() int

Num get found elem num. only valid after finding.

func (*Finder) OnlyFindDir added in v0.6.9

func (f *Finder) OnlyFindDir() *Finder

OnlyFindDir only find dir.

func (*Finder) Reset added in v0.6.9

func (f *Finder) Reset()

Reset filters config setting and results info.

func (*Finder) ResetResult added in v0.6.9

func (f *Finder) ResetResult()

ResetResult reset result info.

func (*Finder) Results added in v0.6.9

func (f *Finder) Results() <-chan Elem

Results find and return founded file Elem. alias of Find()

func (*Finder) ScanDir added in v0.6.9

func (f *Finder) ScanDir(dirPaths ...string) *Finder

ScanDir add source dir for find. alias of AddScanDirs()

func (*Finder) String added in v0.6.9

func (f *Finder) String() string

String all dir paths

func (*Finder) UseAbsPath added in v0.6.9

func (f *Finder) UseAbsPath(enable ...bool) *Finder

UseAbsPath use absolute path for find result. alias of WithUseAbsPath()

func (*Finder) With added in v0.6.9

func (f *Finder) With(fls ...Matcher) *Finder

With add include match matchers. alias of Includes()

func (*Finder) WithConfig added in v0.6.9

func (f *Finder) WithConfig(c *Config) *Finder

WithConfig on the finder

func (*Finder) WithConfigFn added in v0.6.9

func (f *Finder) WithConfigFn(fns ...func(c *Config)) *Finder

WithConfigFn the finder

func (*Finder) WithDir added in v0.6.9

func (f *Finder) WithDir(fls ...Matcher) *Finder

WithDir add exclude dir matchers

func (*Finder) WithDirName added in v0.6.9

func (f *Finder) WithDirName(dirs ...string) *Finder

WithDirName include dir names. alias of IncludeDir()

func (*Finder) WithDirs added in v0.6.9

func (f *Finder) WithDirs(fls []Matcher) *Finder

WithDirs add exclude dir matchers

func (*Finder) WithExts added in v0.6.9

func (f *Finder) WithExts(exts []string) *Finder

WithExts include file exts. alias of IncludeExt()

func (*Finder) WithFileExt added in v0.6.9

func (f *Finder) WithFileExt(exts ...string) *Finder

WithFileExt include file exts. alias of IncludeExt()

func (*Finder) WithFileName added in v0.6.9

func (f *Finder) WithFileName(files ...string) *Finder

WithFileName include file names. alias of IncludeFile()

func (*Finder) WithFilter added in v0.6.9

func (f *Finder) WithFilter(fls ...Matcher) *Finder

WithFilter add include matchers

func (*Finder) WithFlags added in v0.6.9

func (f *Finder) WithFlags(flags FindFlag) *Finder

WithFlags set find flags.

func (*Finder) WithMatchers added in v0.6.9

func (f *Finder) WithMatchers(fls []Matcher) *Finder

WithMatchers add include matchers

func (*Finder) WithMaxDepth added in v0.6.9

func (f *Finder) WithMaxDepth(i int) *Finder

WithMaxDepth set max depth for find.

func (*Finder) WithNames added in v0.6.9

func (f *Finder) WithNames(names []string) *Finder

WithNames include file or dir names. alias of IncludeName()

func (*Finder) WithPaths added in v0.6.9

func (f *Finder) WithPaths(paths []string) *Finder

WithPaths include file or dir paths. alias of IncludePath()

func (*Finder) WithRules added in v0.6.13

func (f *Finder) WithRules(addOrNot bool, rules []string) *Finder

WithRules on the finder

Rule Format:

NAME:pattern1,pattern2

Examples:

ext:.go,.yaml
name:*_test.go,go.mod

func (*Finder) WithStrFlag added in v0.6.9

func (f *Finder) WithStrFlag(s string) *Finder

WithStrFlag set find flags by string.

func (*Finder) WithSubPath added in v0.6.9

func (f *Finder) WithSubPath(paths ...string) *Finder

WithSubPath include file or dir paths. alias of IncludePath()

func (*Finder) WithUseAbsPath added in v0.6.9

func (f *Finder) WithUseAbsPath(enable ...bool) *Finder

WithUseAbsPath use absolute path for find result.

func (*Finder) Without added in v0.6.9

func (f *Finder) Without(fls ...Matcher) *Finder

Without add exclude match matchers. alias of Excludes()

func (*Finder) WithoutDir added in v0.6.9

func (f *Finder) WithoutDir(dirs ...string) *Finder

WithoutDir exclude dir names. alias of ExcludeDir()

func (*Finder) WithoutDotDir added in v0.6.9

func (f *Finder) WithoutDotDir(exclude ...bool) *Finder

WithoutDotDir exclude dot dir names. alias of ExcludeDotDir().

func (*Finder) WithoutDotFile added in v0.6.9

func (f *Finder) WithoutDotFile(exclude ...bool) *Finder

WithoutDotFile exclude dot dir names. alias of ExcludeDotFile().

func (*Finder) WithoutExt added in v0.6.9

func (f *Finder) WithoutExt(exts ...string) *Finder

WithoutExt exclude file exts. alias of ExcludeExt()

func (*Finder) WithoutExts added in v0.6.9

func (f *Finder) WithoutExts(exts []string) *Finder

WithoutExts exclude file exts. alias of ExcludeExt()

func (*Finder) WithoutFile added in v0.6.9

func (f *Finder) WithoutFile(files ...string) *Finder

WithoutFile exclude file names. alias of ExcludeFile()

func (*Finder) WithoutNames added in v0.6.9

func (f *Finder) WithoutNames(names []string) *Finder

WithoutNames exclude file or dir names.

func (*Finder) WithoutPath added in v0.6.9

func (f *Finder) WithoutPath(paths ...string) *Finder

WithoutPath exclude file paths. alias of ExcludePath()

func (*Finder) WithoutPaths added in v0.6.9

func (f *Finder) WithoutPaths(paths []string) *Finder

WithoutPaths exclude file paths. alias of ExcludePath()

type Matcher added in v0.6.9

type Matcher interface {
	// Apply check find elem. return False will skip this file.
	Apply(elem Elem) bool
}

Matcher for match file path.

type MatcherFunc added in v0.6.9

type MatcherFunc func(elem Elem) bool

MatcherFunc for match file info, return False will skip this file

func FileSize added in v0.6.9

func FileSize(min, max uint64) MatcherFunc

FileSize match file by file size. unit: byte

func GlobMatch added in v0.6.9

func GlobMatch(patterns ...string) MatcherFunc

GlobMatch file/dir name by given patterns.

Usage:

f := NewFinder('path/to/dir')
f.AddFilter(GlobMatch("*_test.go"))

func GlobMatches added in v0.6.9

func GlobMatches(patterns []string) MatcherFunc

GlobMatches file/dir name by given patterns.

func HumanModTime added in v0.6.9

func HumanModTime(expr string) MatcherFunc

HumanModTime filter file by modify time string.

Usage:

f := finder.NewFinder()
f.Include(HumanModTime(">10m")) // before 10 minutes
f.Include(HumanModTime("<10m")) // latest 10 minutes, to Now

func HumanSize added in v0.6.9

func HumanSize(expr string) MatcherFunc

HumanSize match file by file size string. eg: ">1k", "<2m", "1g~3g"

func MatchDotDir added in v0.6.9

func MatchDotDir() MatcherFunc

MatchDotDir match dot dirname. eg: ".idea"

func MatchDotFile added in v0.6.9

func MatchDotFile() MatcherFunc

MatchDotFile match dot filename. eg: ".idea"

func MatchExt added in v0.6.9

func MatchExt(exts ...string) MatcherFunc

MatchExt match filepath by given file ext.

Usage:

f := NewFinder('path/to/dir')
f.Add(MatchExt(".go"))
f.Not(MatchExt(".md"))

func MatchExts added in v0.6.9

func MatchExts(exts []string) MatcherFunc

MatchExts filter filepath by given file ext.

func MatchModTime added in v0.6.9

func MatchModTime(start, end time.Time) MatcherFunc

MatchModTime filter file by modify time.

func MatchMtime added in v0.6.9

func MatchMtime(start, end time.Time) MatcherFunc

MatchMtime match file by modify time.

Note: if time is zero, it will be ignored.

Usage:

f := NewFinder('path/to/dir')
// -600 seconds to now(last 10 minutes)
f.AddFile(MatchMtime(timex.NowAddSec(-600), timex.ZeroTime))
// before 600 seconds(before 10 minutes)
f.AddFile(MatchMtime(timex.ZeroTime, timex.NowAddSec(-600)))

func MatchName added in v0.6.9

func MatchName(names ...string) MatcherFunc

MatchName match filepath by given names.

Usage:

f := NewFinder('path/to/dir')
f.Not(MatchName("README.md", "*_test.go"))

func MatchNames added in v0.6.9

func MatchNames(names []string) MatcherFunc

MatchNames match filepath by given names or patterns.

Usage:

f.Not(MatchNames([]string{"README.md", "*_test.go"}))

func MatchPath added in v0.6.9

func MatchPath(subPaths ...string) MatcherFunc

MatchPath match file/dir by given sub paths.

Usage:

f := NewFinder('path/to/dir')
f.Add(MatchPath("need/path"))

func MatchPaths added in v0.6.9

func MatchPaths(subPaths []string) MatcherFunc

MatchPaths match file/dir by given sub paths.

func MatchPrefix added in v0.6.9

func MatchPrefix(prefixes ...string) MatcherFunc

MatchPrefix match filepath by check given prefixes.

Usage:

f := NewFinder('path/to/dir')
f.Add(finder.MatchPrefix("app_", "README"))

func MatchPrefixes added in v0.6.9

func MatchPrefixes(prefixes []string) MatcherFunc

MatchPrefixes match filepath by check given prefixes.

func MatchSuffix added in v0.6.9

func MatchSuffix(suffixes ...string) MatcherFunc

MatchSuffix match filepath by check path has suffixes.

Usage:

f := NewFinder('path/to/dir')
f.Add(finder.MatchSuffix("util.go", "en.md"))
f.Not(finder.MatchSuffix("_test.go", ".log"))

func MatchSuffixes added in v0.6.9

func MatchSuffixes(suffixes []string) MatcherFunc

MatchSuffixes match filepath by check path has suffixes.

func NameLike added in v0.6.9

func NameLike(patterns ...string) MatcherFunc

NameLike exclude filepath by given name match.

func NameLikes added in v0.6.9

func NameLikes(patterns []string) MatcherFunc

NameLikes filter filepath by given name match.

func RegexMatch added in v0.6.9

func RegexMatch(pattern string) MatcherFunc

RegexMatch match name by given regex pattern

Usage:

f := NewFinder('path/to/dir')
f.AddFilter(RegexMatch(`[A-Z]\w+`))

func SizeRange added in v0.6.9

func SizeRange(min, max uint64) MatcherFunc

SizeRange match file by file size. unit: byte

func StartWithDot added in v0.6.9

func StartWithDot() MatcherFunc

StartWithDot match dot file/dir. eg: ".gitignore"

func (MatcherFunc) Apply added in v0.6.9

func (fn MatcherFunc) Apply(elem Elem) bool

Apply check file path. return False will skip this file.

type MultiMatcher added in v0.6.10

type MultiMatcher struct {
	Before   Matcher
	Matchers []Matcher
}

MultiMatcher wrapper for multi matchers

func NewDirMatchers added in v0.6.10

func NewDirMatchers(fls ...Matcher) *MultiMatcher

NewDirMatchers create a new dir matchers

func NewFileMatchers added in v0.6.10

func NewFileMatchers(fls ...Matcher) *MultiMatcher

NewFileMatchers create a new dir matchers

func (*MultiMatcher) Add added in v0.6.10

func (mf *MultiMatcher) Add(fls ...Matcher)

Add matchers

func (*MultiMatcher) Apply added in v0.6.10

func (mf *MultiMatcher) Apply(el Elem) bool

Apply check file path is match.

Jump to

Keyboard shortcuts

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