Documentation
¶
Overview ¶
Package vm exposes the capabilities of a Jsonnet VM as a narrow interface. The returned implementation is automatically set up with the native functions and importers that qbec supports and is safe for concurrent use.
Example ¶
package main
import (
"fmt"
"github.com/splunk/qbec/vm"
)
func main() {
jvm := vm.New(vm.Config{})
code := `
function (str, num) {
foo: str,
bar: num,
baz: std.extVar('baz'),
}
`
vs := vm.VariableSet{}.
WithTopLevelVars(
vm.NewVar("str", "hello"),
vm.NewCodeVar("num", "10"),
).
WithVars(
vm.NewVar("baz", "world"),
)
out, err := jvm.EvalCode("inline-code.jsonnet", vm.MakeCode(code), vs)
if err != nil {
panic(err)
}
fmt.Println(out)
}
Output: { "bar": 10, "baz": "world", "foo": "hello" }
Index ¶
- type Code
- type Config
- type VM
- type Var
- type VariableSet
- func (vs VariableSet) HasTopLevelVar(name string) bool
- func (vs VariableSet) HasVar(name string) bool
- func (vs VariableSet) TopLevelVars() []Var
- func (vs VariableSet) Vars() []Var
- func (vs VariableSet) WithTopLevelVars(add ...Var) VariableSet
- func (vs VariableSet) WithVars(add ...Var) VariableSet
- func (vs VariableSet) WithoutTopLevel() VariableSet
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Code ¶
type Code struct {
// contains filtered or unexported fields
}
Code wraps string to distinguish it from string file names
type Config ¶
type Config struct {
LibPaths []string // library paths
DataSources []datasource.DataSource // data sources
}
Config is the configuration of the VM
type VM ¶
type VM interface {
// EvalFile evaluates the supplied file initializing the VM with the supplied variables
// and returns its output as a JSON string.
EvalFile(file string, v VariableSet) (string, error)
// EvalCode evaluates the supplied code initializing the VM with the supplied variables
// and returns its output as a JSON string.
EvalCode(diagnosticFile string, code Code, v VariableSet) (string, error)
// LintCode uses the jsonnet linter to lint the code and returns any errors
LintCode(diagnosticFile string, code Code) error
}
VM provides a narrow interface to the capabilities of a jsonnet VM.
type Var ¶
type Var struct {
Name string
// contains filtered or unexported fields
}
Var is an opaque variable to be initialized for the jsonnet VM
func NewCodeVar ¶
NewCodeVar returns a variable that has a code value
type VariableSet ¶
type VariableSet struct {
// contains filtered or unexported fields
}
VariableSet is an immutable set of variables to be registered with a jsonnet VM
func (VariableSet) HasTopLevelVar ¶
func (vs VariableSet) HasTopLevelVar(name string) bool
HasTopLevelVar returns true if the specified TLA variable is defined.
func (VariableSet) HasVar ¶
func (vs VariableSet) HasVar(name string) bool
HasVar returns true if the specified external variable is defined.
func (VariableSet) TopLevelVars ¶
func (vs VariableSet) TopLevelVars() []Var
TopLevelVars returns the string top-level variables defined for this variable set.
func (VariableSet) Vars ¶
func (vs VariableSet) Vars() []Var
Vars returns the names of all variables defined for this variable set.
func (VariableSet) WithTopLevelVars ¶
func (vs VariableSet) WithTopLevelVars(add ...Var) VariableSet
WithTopLevelVars returns a variable set with additional top-level string variables in its environment.
func (VariableSet) WithVars ¶
func (vs VariableSet) WithVars(add ...Var) VariableSet
WithVars returns a variable set with additional variables in its environment.
func (VariableSet) WithoutTopLevel ¶
func (vs VariableSet) WithoutTopLevel() VariableSet
WithoutTopLevel returns a variable set that does not have any top level variables set.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package datasource declares the data source interface.
|
Package datasource declares the data source interface. |
|
internal
|
|
|
Package vmutil exposes specific functions used in the native implementation of the VM for general purpose use.
|
Package vmutil exposes specific functions used in the native implementation of the VM for general purpose use. |