Documentation ¶
Overview ¶
Package importer implements custom importers for go-jsonnet.
Custom importers extend the original importers with extra functionality, like the support for glob pattern, so that a user can import multiple files at once.
Index ¶
- Variables
- type FallbackFileImporter
- type GlobImporter
- func (g *GlobImporter) AddAliasPrefix(alias, prefix string) error
- func (g GlobImporter) CanHandle(path string) bool
- func (g *GlobImporter) Exclude(pattern string)
- func (g *GlobImporter) Import(importedFrom, importedPath string) (jsonnet.Contents, string, error)
- func (g *GlobImporter) Logger(logger *zap.Logger)
- func (g GlobImporter) Prefixa() []string
- type Importer
- type MultiImporter
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoImporter = errors.New("no importer") ErrUnknownPrefix = errors.New("unknown prefix") ErrMalformedAlias = errors.New("malformed alias") ErrMalformedGlobPattern = errors.New("malformed glob pattern") ErrImportCycle = errors.New("import cycle") ErrEmptyResult = errors.New("empty result") ErrUnknownConfig = errors.New("unknown config") ErrMalformedImport = errors.New("malformed import string") ErrMalformedQuery = errors.New("malformed query parameter(s)") )
Functions ¶
This section is empty.
Types ¶
type FallbackFileImporter ¶
type FallbackFileImporter struct {
*jsonnet.FileImporter
}
FallbackFileImporter is a wrapper for the original go-jsonnet FileImporter. The idea is to provide a chain for importers in the MultiImporter, with the FileImporter as fallback, if nothing else can handle the given import prefix (and of course also no prefix).
func NewFallbackFileImporter ¶
func NewFallbackFileImporter(jpaths ...string) *FallbackFileImporter
NewFallbackFileImporter returns finally the original go-jsonnet FileImporter. As optional parameters extra library search paths (aka. jpath) can be provided too.
func (*FallbackFileImporter) CanHandle ¶
func (f *FallbackFileImporter) CanHandle(_ string) bool
CanHandle method of the FallbackFileImporter returns always true.
func (*FallbackFileImporter) Logger ¶
func (f *FallbackFileImporter) Logger(_ *zap.Logger)
Logger implements the Logger interface method, but does not do anything as the FallbackFileImporter is just a wrapper for the go-jsonnet FileImporter.
func (*FallbackFileImporter) Prefixa ¶
func (f *FallbackFileImporter) Prefixa() []string
Prefixa for the FallbackFileImporter returns an empty list.
type GlobImporter ¶
type GlobImporter struct { // JPaths stores extra search paths. JPaths []string // contains filtered or unexported fields }
GlobImporter can be used to allow import-paths with glob patterns inside. Continuous imports are also possible and allow glob pattern in resolved file/contents. Activate the glob-import via the following prefixa in front of the import path definition (see README file):
- `glob.<?>://`, where <?> can be one of [path, file, dir, stem]
- `glob.<?>+://`, where <?> can be one of [file, dir, stem]
- `glob+://`
For `glob.<?>://` all resolved files will stored under its path, file(name), dir(name), stem (filename without extension). If multiple files would fit for the file, dirs or stem, only the last one will be used. Example:
- Folders/files:
- a.libsonnet
- subfolder/a.libsonnet
- Import path:
- import 'glob.stem://**/*.libsonnet'
- Result: { a: (import 'subfolder/a.libsonnet'); }
func NewGlobImporter ¶
func NewGlobImporter(jpaths ...string) *GlobImporter
NewGlobImporter returns a GlobImporter with default prefixa.
func (*GlobImporter) AddAliasPrefix ¶
func (g *GlobImporter) AddAliasPrefix(alias, prefix string) error
AddAliasPrefix binds a given alias to a given prefix. This prefix must exist and only one alias per prefix is possible. An alias must have the suffix "://".
func (GlobImporter) CanHandle ¶
func (g GlobImporter) CanHandle(path string) bool
CanHandle implements the interface method of the Importer and returns true, if the path has on of the supported prefixa. Run <Importer>.Prefixa() to get the supported prefixa.
func (*GlobImporter) Exclude ¶
func (g *GlobImporter) Exclude(pattern string)
func (*GlobImporter) Import ¶
func (g *GlobImporter) Import(importedFrom, importedPath string) (jsonnet.Contents, string, error)
Import implements the go-jsonnet iterface method and converts the resolved paths into readable paths for the original go-jsonnet FileImporter.
func (*GlobImporter) Logger ¶
func (g *GlobImporter) Logger(logger *zap.Logger)
Logger can be used to set the zap.Logger for the GlobImporter.
func (GlobImporter) Prefixa ¶
func (g GlobImporter) Prefixa() []string
Prefixa returns the list of supported prefixa for this importer.
type Importer ¶
type Importer interface { jsonnet.Importer // CanHandle will be used to decide if an importer can handle the given // import path. CanHandle(path string) bool // Logger can be used to set a zap.Logger for the importer. // (see https://pkg.go.dev/go.uber.org/zap) Logger(*zap.Logger) // Prefixa returns the list of prefixa, which will trigger the specific // importer. An empty list means no prefix used/needed. Prefixa() []string // contains filtered or unexported methods }
Importer extends the jsonnet importer interface and adds a method to get the right importer for a given path.
type MultiImporter ¶
type MultiImporter struct {
// contains filtered or unexported fields
}
MultiImporter supports multiple importers and tries to find the right importer from a list of importers.
func NewMultiImporter ¶
func NewMultiImporter(importers ...Importer) *MultiImporter
NewMultiImporter returns an instance of a MultiImporter with default settings, like all custom importers + fallback importer.
func (*MultiImporter) IgnoreImportCycles ¶
func (m *MultiImporter) IgnoreImportCycles()
IgnoreImportCycles disables the test for import cycles and therefore also any error in that regard.
func (*MultiImporter) Import ¶
func (m *MultiImporter) Import(importedFrom, importedPath string) (jsonnet.Contents, string, error)
Import is used by go-jsonnet to run this importer. It implements the go-jsonnet Importer interface method.
func (*MultiImporter) Logger ¶
func (m *MultiImporter) Logger(logger *zap.Logger)
Logger method can be used to set a zap.Logger for all importers at once. (see https://pkg.go.dev/go.uber.org/zap)
func (*MultiImporter) SetImportGraphFile ¶
func (m *MultiImporter) SetImportGraphFile(name string)