Documentation ¶
Index ¶
- type CachedLoader
- type FilesystemLoader
- func MustNewFileSystemLoader(searchPaths ...string) *FilesystemLoader
- func MustNewFileSystemLoaderWithOptions(encoding encoding.Encoding, followLinks bool, searchPaths ...string) *FilesystemLoader
- func NewFileSystemLoader(searchPaths ...string) (*FilesystemLoader, error)
- func NewFileSystemLoaderWithOptions(encoding encoding.Encoding, followLinks bool, searchPaths ...string) (loader *FilesystemLoader, err error)
- type Loader
- type MergedLoader
- type NullLoader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CachedLoader ¶
type CachedLoader struct {
// contains filtered or unexported fields
}
CachedLoader represents a cached loader for templates. It wraps another loader and caches the loaded templates.
func NewCachedLoader ¶
func NewCachedLoader(loader Loader) *CachedLoader
NewCachedLoader creates a new CachedLoader.
func (*CachedLoader) Load ¶
func (fs *CachedLoader) Load(name string, cfg *exec.EvalConfig) (*exec.Template, error)
Load returns a template by name.
type FilesystemLoader ¶
type FilesystemLoader struct {
// contains filtered or unexported fields
}
FilesystemLoader represents a local filesystem loader for templates.
Search paths can be relative or absolute. Relative paths are relative to the current working directory. For security reasons, the loader prevents access to files outside of the search paths. This means that path traversal using `../` is not possible.
If you want to improve performance, you can use the CachedLoader to cache the loaded templates. Simply wrap the FilesystemLoader with the CachedLoader like this:
loader := loaders.NewCachedLoader(loaders.MustNewFileSystemLoader("templates"))
func MustNewFileSystemLoader ¶
func MustNewFileSystemLoader(searchPaths ...string) *FilesystemLoader
MustNewFileSystemLoader creates a new FilesystemLoader. It panics if an error occurs.
func MustNewFileSystemLoaderWithOptions ¶
func MustNewFileSystemLoaderWithOptions( encoding encoding.Encoding, followLinks bool, searchPaths ...string, ) *FilesystemLoader
MustNewFileSystemLoaderWithOptions creates a new FilesystemLoader with the given options. It panics if an error occurs.
func NewFileSystemLoader ¶
func NewFileSystemLoader(searchPaths ...string) (*FilesystemLoader, error)
NewFileSystemLoader creates a new FilesystemLoader.
func NewFileSystemLoaderWithOptions ¶
func NewFileSystemLoaderWithOptions( encoding encoding.Encoding, followLinks bool, searchPaths ...string, ) (loader *FilesystemLoader, err error)
NewFileSystemLoaderWithOptions creates a new FilesystemLoader with the given options. Mind that the files are searched in the order of the given search paths.
- encoding: The encoding of the template files. If nil, the default encoding is used.
- followLinks: If true, symlinks are followed.
- searchPaths: The paths to search for templates. The paths can be relative or absolute. Relative paths are relative to the current working directory.
func (*FilesystemLoader) Load ¶
func (fs *FilesystemLoader) Load(name string, cfg *exec.EvalConfig) (*exec.Template, error)
Load returns a template by name.
type Loader ¶
type Loader interface { // Load returns a template by name. Load(name string, cfg *exec.EvalConfig) (*exec.Template, error) }
Loader is an interface for loading templates by name.
type MergedLoader ¶
type MergedLoader struct {
// contains filtered or unexported fields
}
MergedLoader represents a merged loader for templates. It wraps multiple loaders and returns the first found template.
func NewMergedLoader ¶
func NewMergedLoader(loaders ...Loader) *MergedLoader
NewMergedLoader creates a new MergedLoader.
func (*MergedLoader) Load ¶
func (fs *MergedLoader) Load(name string, cfg *exec.EvalConfig) (*exec.Template, error)
Load returns a template by name.
type NullLoader ¶
type NullLoader struct{}
NullLoader represents a loader that refuses to load anything.
func (*NullLoader) Load ¶
func (fs *NullLoader) Load(name string, _ *exec.EvalConfig) (*exec.Template, error)
Load returns a template by name.