Documentation
¶
Overview ¶
Package ripgo provides high-level APIs for searching file contents and finding filesystem paths.
It orchestrates traversal (walk), filtering (ignore), and matching (pattern and find) into simple streaming interfaces for library consumers.
Basic Usage ¶
The primary entry point is the Search function, which returns an iterator of results:
ctx := context.Background()
results := ripgo.Search(ctx, "TODO", []string{"."}, ripgo.WithIgnoreCase(true))
for res, err := range results {
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
continue
}
fmt.Printf("%s: %d matches\n", res.Path, len(res.Matches))
}
Finding Paths ¶
Find matches names and metadata without reading file contents:
for result, err := range ripgo.Find(ctx, `\.go$`, []string{"."},
ripgo.WithFindType(find.TypeFile)) {
if err != nil {
continue
}
fmt.Println(result.Path)
}
Functional Options ¶
Search can be configured using functional options:
- WithMultiline(true): Enable multiline matching across line boundaries.
- WithWordRegexp(true): Match whole words only.
- WithContext(before, after): Include context lines around matches.
- WithReplace("template"): Perform string replacement using capture groups.
- WithPcre2(true): Use the PCRE2 regex engine instead of Go's default.
Filesystem Abstraction ¶
ripgo works with any io/fs.FS implementation via the WithFS option. This allows searching in-memory files, zip archives, or remote storage:
myFS := fstest.MapFS{...}
results := ripgo.Search(ctx, "pattern", []string{"."}, ripgo.WithFS(myFS))
Architecture ¶
The project is divided into several focused packages:
- github.com/nijaru/ripgo/search: File scanning and match reporting.
- github.com/nijaru/ripgo/find: Filename, path, and metadata matching.
- github.com/nijaru/ripgo/pattern: Multi-engine pattern matching (Literal, Regex, PCRE2).
- github.com/nijaru/ripgo/walk: Parallel directory traversal.
- github.com/nijaru/ripgo/fsref: Capability-backed file access.
- github.com/nijaru/ripgo/ignore: Gitignore-compatible filtering logic.
Package ripgo provides high-level APIs for searching file contents and finding filesystem paths.
It orchestrates the walk, ignore, pattern, search, and find packages into simple, unified interfaces for library consumers.
Index ¶
- func DefaultFindConfig(pattern string) findpkg.Config
- func Find(ctx context.Context, pattern string, paths []string, opts ...FindOption) iter.Seq2[findpkg.Result, error]
- func Search(ctx context.Context, patternStr string, paths []string, opts ...Option) iter.Seq2[search.Result, error]
- type Config
- type FindOption
- func WithFindExtension(extension string) FindOption
- func WithFindExtensions(extensions ...string) FindOption
- func WithFindFS(fsys fs.FS) FindOption
- func WithFindFixedStrings(v bool) FindOption
- func WithFindFollowSymlinks(v bool) FindOption
- func WithFindFullPath(v bool) FindOption
- func WithFindGlob(v bool) FindOption
- func WithFindGlobExcludes(globs ...string) FindOption
- func WithFindHidden(v bool) FindOption
- func WithFindIgnoreCase(v bool) FindOption
- func WithFindMaxDepth(depth int) FindOption
- func WithFindMaxSize(size int64) FindOption
- func WithFindMetadata(v bool) FindOption
- func WithFindMinDepth(depth int) FindOption
- func WithFindMinSize(size int64) FindOption
- func WithFindNoIgnore(v bool) FindOption
- func WithFindThreads(n int) FindOption
- func WithFindType(typ findpkg.Type) FindOption
- func WithFindTypes(types ...findpkg.Type) FindOption
- type Option
- func WithContext(before, after int) Option
- func WithFS(fsys fs.FS) Option
- func WithFixedStrings(v bool) Option
- func WithFollowSymlinks(v bool) Option
- func WithGlobExcludes(globs ...string) Option
- func WithGlobIncludes(globs ...string) Option
- func WithHidden(v bool) Option
- func WithIgnoreCase(v bool) Option
- func WithMatcher(m pattern.Matcher) Option
- func WithMaxCount(n int) Option
- func WithMaxFileSize(n int64) Option
- func WithMultiline(v bool) Option
- func WithNoIgnore(v bool) Option
- func WithOnlyMatching(v bool) Option
- func WithPcre2(v bool) Option
- func WithReplace(v string) Option
- func WithThreads(n int) Option
- func WithTypes(types []string) Option
- func WithTypesNot(typesNot []string) Option
- func WithWordRegexp(v bool) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultFindConfig ¶
DefaultFindConfig returns a finder configuration with pattern matching enabled and the shared walker's zero-value traversal defaults.
func Find ¶
func Find(ctx context.Context, pattern string, paths []string, opts ...FindOption) iter.Seq2[findpkg.Result, error]
Find streams matching paths from the supplied roots without reading file contents. It returns an iterator of (Result, error). A missing path or traversal failure is yielded as an error; the iterator stops when the caller stops yielding.
func Search ¶
func Search(ctx context.Context, patternStr string, paths []string, opts ...Option) iter.Seq2[search.Result, error]
Search performs a complete search using the provided configuration and paths. It returns an iterator of (Result, error). The error is non-nil if a file-level error was encountered (e.g. Permission Denied).
Types ¶
type Config ¶
type Config struct {
Pattern pattern.Config
Search search.Config
Walk walk.Config
Ignore ignore.Config
FS fs.FS
Matcher pattern.Matcher
}
Config represents the complete search configuration.
func DefaultConfig ¶
DefaultConfig returns a configuration with sensible defaults.
type FindOption ¶
FindOption configures Find.
func WithFindExtension ¶
func WithFindExtension(extension string) FindOption
WithFindExtension adds an extension filter. Repeated values are ORed.
func WithFindExtensions ¶
func WithFindExtensions(extensions ...string) FindOption
WithFindExtensions adds extension filters. Repeated values are ORed.
func WithFindFS ¶
func WithFindFS(fsys fs.FS) FindOption
WithFindFS selects the filesystem used by Find.
func WithFindFixedStrings ¶
func WithFindFixedStrings(v bool) FindOption
WithFindFixedStrings enables literal substring matching.
func WithFindFollowSymlinks ¶
func WithFindFollowSymlinks(v bool) FindOption
WithFindFollowSymlinks enables followed directory symlinks.
func WithFindFullPath ¶
func WithFindFullPath(v bool) FindOption
WithFindFullPath matches normalized paths relative to each search root.
func WithFindGlobExcludes ¶
func WithFindGlobExcludes(globs ...string) FindOption
WithFindGlobExcludes excludes matching paths from finder traversal.
func WithFindIgnoreCase ¶
func WithFindIgnoreCase(v bool) FindOption
WithFindIgnoreCase enables case-insensitive matching and extension filters.
func WithFindMaxDepth ¶
func WithFindMaxDepth(depth int) FindOption
WithFindMaxDepth sets the inclusive maximum root-relative depth.
func WithFindMaxSize ¶
func WithFindMaxSize(size int64) FindOption
WithFindMaxSize sets the inclusive maximum metadata size.
func WithFindMetadata ¶
func WithFindMetadata(v bool) FindOption
WithFindMetadata controls whether finder results resolve file metadata. Metadata is enabled by default; disabling it leaves Result.Info nil and cannot be combined with size filters.
func WithFindMinDepth ¶
func WithFindMinDepth(depth int) FindOption
WithFindMinDepth sets the inclusive minimum root-relative depth.
func WithFindMinSize ¶
func WithFindMinSize(size int64) FindOption
WithFindMinSize sets the inclusive minimum metadata size.
func WithFindNoIgnore ¶
func WithFindNoIgnore(v bool) FindOption
WithFindNoIgnore disables ignore-file loading.
func WithFindThreads ¶
func WithFindThreads(n int) FindOption
WithFindThreads sets the finder traversal worker count.
func WithFindType ¶
func WithFindType(typ findpkg.Type) FindOption
WithFindType adds a result type filter. Repeated values are ORed.
func WithFindTypes ¶
func WithFindTypes(types ...findpkg.Type) FindOption
WithFindTypes adds result type filters. Repeated values are ORed.
type Option ¶
type Option func(*Config)
Option is a functional option for configuring the search.
func WithContext ¶
func WithFixedStrings ¶
func WithFollowSymlinks ¶
func WithGlobExcludes ¶
func WithGlobIncludes ¶
func WithHidden ¶
func WithIgnoreCase ¶
func WithMatcher ¶
func WithMaxCount ¶
func WithMaxFileSize ¶
func WithMultiline ¶
func WithNoIgnore ¶
func WithOnlyMatching ¶
func WithReplace ¶
func WithThreads ¶
func WithTypesNot ¶
func WithWordRegexp ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
ripgo
command
|
|
|
Package find provides filename and path matching for finder mode.
|
Package find provides filename and path matching for finder mode. |
|
Package fsref defines capability-backed file references used by search and traversal.
|
Package fsref defines capability-backed file references used by search and traversal. |
|
Package ignore implements gitignore-compatible file filtering.
|
Package ignore implements gitignore-compatible file filtering. |
|
internal
|
|
|
action
Package action implements the private, opt-in side effects of finder mode.
|
Package action implements the private, opt-in side effects of finder mode. |
|
aho
Package aho implements a minimal Aho-Corasick automaton for multi-literal pre-filtering.
|
Package aho implements a minimal Aho-Corasick automaton for multi-literal pre-filtering. |
|
osfs
Package osfs provides an fs.FS implementation for the local OS filesystem.
|
Package osfs provides an fs.FS implementation for the local OS filesystem. |
|
Package printer implements various output formats for search results.
|
Package printer implements various output formats for search results. |
|
Package stats provides search statistics tracking.
|
Package stats provides search statistics tracking. |
|
Package walk implements parallel directory traversal.
|
Package walk implements parallel directory traversal. |