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 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 DefaultProvider = sync.OnceValue( func() fsimpl.FSProvider { fsp := fsimpl.NewMux() fsp.Add(autofs.FS) fsp.Add(wdFSProvider) fsp.Add(EnvFS) fsp.Add(StdinFS) fsp.Add(mergeFSProvider) return fsp })()
DefaultProvider is the default filesystem provider used by gomplate
var EnvFS = fsimpl.FSProviderFunc(newEnvFS, "env")
var StdinFS = fsimpl.FSProviderFunc(newStdinFS, "stdin")
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 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