Documentation ¶
Index ¶
- Variables
- func ContextWithFSProvider(ctx context.Context, fsp fsimpl.FSProvider) context.Context
- func ContextWithStdin(ctx context.Context, r io.Reader) context.Context
- func DirInfo(name string, modTime time.Time) fs.FileInfo
- func ExpandEnvFsys(fsys fs.FS, s string) string
- func FSProviderFromContext(ctx context.Context) fsimpl.FSProvider
- func FSysForPath(ctx context.Context, path string) (fs.FS, error)
- func FileInfo(name string, size int64, mode fs.FileMode, modTime time.Time, ...) fs.FileInfo
- func FileInfoDirEntry(fi fs.FileInfo) fs.DirEntry
- func GetenvFsys(fsys fs.FS, key string, def ...string) string
- func LookupEnvFsys(fsys fs.FS, key string) (string, bool)
- func NewEnvFS(_ *url.URL) (fs.FS, error)
- func NewMergeFS(u *url.URL) (fs.FS, error)
- func NewStdinFS(_ *url.URL) (fs.FS, error)
- func ResolveLocalPath(fsys fs.FS, name string) (root, resolved string, err error)
- func SplitFSMuxURL(in *url.URL) (*url.URL, string)
- func StdinFromContext(ctx context.Context) io.Reader
- func WithDataSourceRegistryFS(registry Registry, fsys fs.FS) fs.FS
- func WrapWdFS(fsys fs.FS) fs.FS
- func WrappedFSProvider(fsys fs.FS, schemes ...string) fsimpl.FSProvider
- type DataSourceReader
- type Registry
Constants ¶
This section is empty.
Variables ¶
var EnvFS = fsimpl.FSProviderFunc(NewEnvFS, "env")
var MergeFS = fsimpl.FSProviderFunc(NewMergeFS, "merge")
var StdinFS = fsimpl.FSProviderFunc(NewStdinFS, "stdin")
var WdFS = fsimpl.FSProviderFunc( func(u *url.URL) (fs.FS, error) { if !isSupportedPath(u.Path) { return nil, fmt.Errorf("unsupported path %q: %w", u.Path, fs.ErrInvalid) } vol, _, err := ResolveLocalPath(nil, u.Path) if err != nil { return nil, fmt.Errorf("resolve %q: %w", u.Path, err) } var fsys fs.FS if vol == "" || vol == "/" { fsys = osfs.NewFS() } else { var err error fsys, err = osfs.NewFS().SubVolume(vol) if err != nil { return nil, err } } return &wdFS{vol: vol, fsys: fsys}, nil }, "file", "", )
WdFS is a filesystem provider that creates local filesystems which support absolute paths beginning with '/', and interpret relative paths as relative to the current working directory (as reported by os.Getwd).
On Windows, certain types of paths are not supported, and will return an error. These are: - Drive Relative - e.g. C:foo\bar - Root Local - e.g. \\. or \\? - non-drive Local Devices - e.g. \\.\COM1, \\.\pipe\foo - NT Paths - e.g. \??\C:\foo\bar or \??\UNC\foo\bar
Functions ¶
func ContextWithFSProvider ¶
ContextWithFSProvider returns a context with the given FSProvider. Should only be used in tests.
func ContextWithStdin ¶
ContextWithStdin injects an io.Reader into the context, which can be used to override the default stdin.
func DirInfo ¶
DirInfo creates a fs.FileInfo for a directory with the given name. Use FileInfo to set other values.
func ExpandEnvFsys ¶
ExpandEnvFsys - a convenience function intended for internal use only!
func FSProviderFromContext ¶
FSProviderFromContext returns the FSProvider from the context, if any
func FSysForPath ¶
FSysForPath returns an io/fs.FS for the given path (which may be an URL), rooted at /. A fsimpl.FSProvider is required to be present in ctx, otherwise an error is returned.
func FileInfo ¶
func FileInfo(name string, size int64, mode fs.FileMode, modTime time.Time, contentType string) fs.FileInfo
FileInfo creates a static fs.FileInfo with the given properties. The result is also a fs.DirEntry and can be safely cast.
func FileInfoDirEntry ¶
FileInfoDirEntry adapts a fs.FileInfo into a fs.DirEntry. If it doesn't already implement fs.DirEntry, it will be wrapped to always return the same fs.FileInfo.
func GetenvFsys ¶
GetenvFsys - a convenience function intended for internal use only!
func LookupEnvFsys ¶ added in v4.2.0
LookupEnvFsys - a convenience function intended for internal use only!
func NewEnvFS ¶
NewEnvFS returns a filesystem (an fs.FS) that can be used to read data from environment variables.
func NewMergeFS ¶
NewMergeFS returns a new filesystem that merges the contents of multiple paths. Only a URL like "merge:" or "merge:///" makes sense here - the piped-separated lists of sub-sources to merge must be given to Open.
You can use WithDataSourceRegistryFS to provide the datasource registry, otherwise, an empty registry will be used.
An FSProvider will also be needed, which can be provided with a context using ContextWithFSProvider. Provide that context with fsimpl.WithContextFS.
func NewStdinFS ¶
NewStdinFS returns a filesystem (an fs.FS) that can be used to read data from standard input (os.Stdin).
func ResolveLocalPath ¶
ResolveLocalPath resolves a path on the given filesystem, relative to the current working directory, and returns both the root (/ or a volume name on Windows) and the resolved path. If the path is absolute (e.g. starts with a `/` or volume name on Windows), it is split and returned as-is. If fsys is nil, the current working directory is used. The output is suitable for use with io/fs functions.
func SplitFSMuxURL ¶
SplitFSMuxURL splits a URL into a filesystem URL and a relative file path
func StdinFromContext ¶
StdinFromContext returns the io.Reader that should be used for stdin as injected by ContextWithStdin. If no reader has been injected, os.Stdin is returned.
func WithDataSourceRegistryFS ¶
WithDataSourceRegistryFS injects a datasource registry into the filesystem fs, if the filesystem supports it (i.e. has a WithDataSourceRegistry method). This is used for the mergefs filesystem.
func WrapWdFS ¶
WrapWdFS is a filesystem wrapper that assumes non-absolute paths are relative to the current working directory (as reported by os.Getwd). It only works in a meaningful way when used with a local filesystem (e.g. os.DirFS or hackpadfs/os.FS).
func WrappedFSProvider ¶
WrappedFSProvider is an FSProvider that returns the given fs.FS
Types ¶
type DataSourceReader ¶
type DataSourceReader interface { // ReadSource reads the content of a datasource, given an alias and optional // arguments. If the datasource is not found, the alias is interpreted as a // URL. If the alias is not a valid URL, an error is returned. // // Returned content is cached, so subsequent calls with the same alias and // arguments will return the same content. ReadSource(ctx context.Context, alias string, args ...string) (string, []byte, error) // contains registry Registry }
DataSourceReader reads content from a datasource
func NewSourceReader ¶
func NewSourceReader(reg Registry) DataSourceReader
type Registry ¶
type Registry interface { // Register a datasource Register(alias string, ds config.DataSource) // Lookup a registered datasource Lookup(alias string) (config.DataSource, bool) // List registered datasource aliases List() []string // Add extra headers not attached to a pre-defined datasource. These can be // used by datasources registered at runtime. AddExtraHeader(alias string, hdr http.Header) }
Registry - a registry of datasources
func NewRegistry ¶
func NewRegistry() Registry