importers

package
v0.14.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompositeImporter

type CompositeImporter struct {
	// contains filtered or unexported fields
}

CompositeImporter tries multiple extended importers in sequence for a given path

func NewCompositeImporter

func NewCompositeImporter(importers ...ExtendedImporter) *CompositeImporter

NewCompositeImporter creates a composite importer with the supplied extended importers. Note that if two importers could match the same path, the first one will be used so order is important.

func (*CompositeImporter) CanProcess added in v0.14.0

func (c *CompositeImporter) CanProcess(importedPath string) bool

CanProcess implements the interface method of the ExtendedImporter

func (*CompositeImporter) Import

func (c *CompositeImporter) Import(importedFrom, importedPath string) (contents jsonnet.Contents, foundAt string, err error)

Import implements the interface method by delegating to installed importers in sequence

type DataSource added in v0.14.0

type DataSource interface {
	// Name returns the name of this data source and is used to determine if
	// an import path should be processed by the data source importer.
	Name() string
	// Resolve resolves the absolute path defined for the data source to a string.
	Resolve(path string) (string, error)
}

DataSource is a named delegate that can resolve import paths. Multiple VMs may access a single instance of a data source. Thus, data source implementations must be safe for concurrent use.

type DataSourceImporter added in v0.14.0

type DataSourceImporter struct {
	// contains filtered or unexported fields
}

DataSourceImporter implements an importer that delegates to a data source for resolution.

func NewDataSourceImporter added in v0.14.0

func NewDataSourceImporter(source DataSource) *DataSourceImporter

NewDataSourceImporter returns an importer that can resolve paths for the specified datasource. It processes entries of the form

data://{name}[/{path-to-be-resolved}]

If no path is provided, it is set to "/"

func (*DataSourceImporter) CanProcess added in v0.14.0

func (d *DataSourceImporter) CanProcess(path string) bool

CanProcess implements the interface method

func (*DataSourceImporter) Import added in v0.14.0

func (d *DataSourceImporter) Import(_, importedPath string) (contents jsonnet.Contents, foundAt string, err error)

Import implements the interface method. For the datasource importer, imports are always considered absolute and the import-from path has no significance.

type ExtendedFileImporter

type ExtendedFileImporter struct {
	*jsonnet.FileImporter
}

ExtendedFileImporter wraps a file importer and declares that it can import any path.

func NewFileImporter

func NewFileImporter(jfi *jsonnet.FileImporter) *ExtendedFileImporter

NewFileImporter creates an extended file importer, wrapping the one supplied.

func (*ExtendedFileImporter) CanProcess

func (e *ExtendedFileImporter) CanProcess(_ string) bool

CanProcess implements the interface method.

type ExtendedImporter

type ExtendedImporter interface {
	jsonnet.Importer
	CanProcess(path string) bool
}

ExtendedImporter extends the jsonnet importer interface to add a new method that can determine whether an importer can be used for a path.

type GlobImporter

type GlobImporter struct {
	// contains filtered or unexported fields
}

GlobImporter provides facilities to import a bag of files using a glob pattern. Note that it will NOT honor any library paths and must be exactly resolved from the caller's location. It is initialized with a verb that configures how the inner imports are done (i.e. `import` or `importstr`) and it processes paths that start with `glob-{verb}:`

After the marker prefix is stripped, the input is treated as a file pattern that is resolved using Go's glob functionality. The return value is an object that is keyed by file names relative to the import location with values importing the contents of the file.

That is, given the following directory structure:

lib
	- a.json
	- b.json
caller
	- c.libsonnet

where c.libsonnet has the following contents

import 'glob-import:../lib/*.json'

evaluating `c.libsonnet` will return jsonnet code of the following form:

{
	'../lib/a.json': import '../lib/a.json',
	'../lib/b.json': import '../lib/b.json',
}

func NewGlobImporter

func NewGlobImporter(innerVerb string) *GlobImporter

NewGlobImporter creates a glob importer.

func (*GlobImporter) CanProcess

func (g *GlobImporter) CanProcess(path string) bool

CanProcess implements the interface method, returning true for paths that start with the string "glob:"

func (*GlobImporter) Import

func (g *GlobImporter) Import(importedFrom, importedPath string) (contents jsonnet.Contents, foundAt string, err error)

Import implements the interface method.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL