Custom Filesystems
Overview
Section titled “Overview”gogenfilter uses Go’s fs.FS interface, making it easy to test without real files or to read from custom sources.
Default Behavior
Section titled “Default Behavior”By default, the filter uses os.DirFS(".") (the current working directory):
f := gogenfilter.NewFilter( gogenfilter.Enabled(), gogenfilter.WithFilterOptions(gogenfilter.FilterAll),)// Uses os.DirFS(".") internallyTesting with MapFS
Section titled “Testing with MapFS”Use fstest.MapFS for deterministic, isolated tests:
import "testing/fstest"
mapFS := fstest.MapFS{ "db/models.go": &fstest.MapFile{ Data: []byte("// Code generated by sqlc. DO NOT EDIT.\npackage db\n"), }, "main.go": &fstest.MapFile{ Data: []byte("package main\n"), },}
f := gogenfilter.NewFilter( gogenfilter.Enabled(), gogenfilter.WithFilterOptions(gogenfilter.FilterSQLC), gogenfilter.WithFS(mapFS),)
filtered, _ := f.ShouldFilter("db/models.go") // truefiltered, _ = f.ShouldFilter("main.go") // falseCustom Filesystem
Section titled “Custom Filesystem”Implement fs.FS for any source — embedded files, archives, remote storage:
// With embed.FS//go:embed testdata/*var testdata embed.FS
f := gogenfilter.NewFilter( gogenfilter.Enabled(), gogenfilter.WithFilterOptions(gogenfilter.FilterAll), gogenfilter.WithFS(testdata),)nil Handling
Section titled “nil Handling”Passing nil to WithFS is safe — the filter falls back to os.DirFS(".").