Documentation
¶
Index ¶
- func MatchAnd(matches ...func(filepath string) bool) func(filepath string) bool
- func MatchExt(extension string) func(path string) bool
- func MatchNever(string) bool
- func MatchOr(matches ...func(filepath string) bool) func(filepath string) bool
- func MatchPrefix(prefix string) func(filepath string) bool
- func MatchSuffix(suffix string) func(path string) bool
- func Sub(fileSys fs.FS, path string) fs.FS
- type FileHeader
- type MatchFS
- type MultiFS
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MatchAnd ¶
MatchAnd returns a matcher-func that matches a file if all the given matchers match.
It can be passed any number of matchers.
This allows for more complex logic when matching paths.
func MatchExt ¶
MatchExt returns a matcher-func that matches a file if the given extension matches the file path.
The extension passed to this function is normalized to start with a ".".
When matching, the extension is retrieved from the file path with filepath.Ext and compared to the provided extension.
func MatchNever ¶
MatchNever returns a matcher-func that never matches any file.
func MatchOr ¶
MatchOr returns a matcher-func that matches a file if any of the given matchers match.
It can be passed any number of matchers.
This allows for more complex logic when matching paths.
func MatchPrefix ¶
MatchPrefix returns a matcher-func that matches a file if the given prefix matches the file path.
The prefix is normalized to use "/" as the path separator.
If the prefix is not empty and does not end with a "." or "/", it is appended with a "/".
When matching, the file path is compared to the prefix, the provided path either has to be the prefix or start with the prefix.
func MatchSuffix ¶
MatchSuffix returns a matcher-func that matches a file if the given suffix matches the file path.
The suffix is normalized to use "/" as the path separator.
If the suffix is not empty and does not start with a "." or "/", it is prepended with a "/".
When matching, the file path is compared to the suffix, the provided path either has to be the suffix or end with the suffix.
Types ¶
type FileHeader ¶
type MatchFS ¶
type MatchFS struct {
// contains filtered or unexported fields
}
MatchFS is a filesystem that only allows opening files that match a given matcher-func.
It can be used to restrict access to files in a filesystem.
The matcher-func is called with the path of the file that is being opened.
func NewMatchFS ¶
NewMatchFS creates a new MatchFS filesystem that wraps the given filesystem and only allows opening files that match the given matcher-func.
func (*MatchFS) ForceOpen ¶
ForceOpen opens the file at the given path, even if it does not match the matcher-func.
This allows for bypassing any restrictions that the matcher-func might impose.
type MultiFS ¶
type MultiFS struct {
// contains filtered or unexported fields
}
MultiFS is a filesystem that combines multiple filesystems.
It can be used to combine multiple filesystems into a single filesystem.
When opening a file, it will try to open the file in each filesystem in the order they were added.
It is best (and automatically) used with the `MatchFS` filesystem to restrict access to files in the filesystems.
This allows for faster skipping of filesystems that do not contain the file.
func NewMultiFS ¶
NewMultiFS creates a new MultiFS filesystem that combines the given filesystems.
If no filesystems are given, an empty MultiFS filesystem is created.
func (*MultiFS) Add ¶
Add adds the given filesystem to the MultiFS filesystem.
If a matcher-func is given, it will only allow opening files that match the given matcher-func.
This allows for restricting access to files in the filesystem.
A regular `fs.FS` is added to the pool if no matcher-func is given.
func (*MultiFS) ForceOpen ¶
ForceOpen opens the file at the given path, even if it does not match the matcher-func.
This allows for bypassing any restrictions that the matcher-func of any underlying `MatchFS` might impose.