nodemaker

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2018 License: Apache-2.0 Imports: 8 Imported by: 12

Documentation

Index

Examples

Constants

View Source
const (
	// BopPlus is +
	BopPlus BinaryOp = "+"
	// BopEqual is ==
	BopEqual = "=="
	// BopGreater is >
	BopGreater = ">"
	// BopAnd is &&
	BopAnd = "&&"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Apply

type Apply struct {
	Chainer
	// contains filtered or unexported fields
}

Apply represents an application of a function.

Example
o := NewObject()
k := LocalKey("foo")

arg1 := NewStringDouble("arg1")

a := ApplyCall("alpha.beta.charlie", arg1)

if err := o.Set(k, a); err != nil {
	fmt.Printf("error: %#v\n", err)
}

if err := printer.Fprint(os.Stdout, o.Node()); err != nil {
	fmt.Printf("error: %#v\n", err)
}
Output:

{
  local foo = alpha.beta.charlie('arg1'),
}

func ApplyCall

func ApplyCall(method string, args ...Noder) *Apply

ApplyCall creates an Apply using a method string.

func NewApply

func NewApply(target Chainable, positionalArgs []Noder, optionalArgs []OptionalArg) *Apply

NewApply creates an instance of Apply.

func (*Apply) Node

func (a *Apply) Node() ast.Node

Node converts the Apply to a jsonnet ast node.

func (*Apply) SetTarget

func (a *Apply) SetTarget(c Chainable)

SetTarget sets the target of this Apply.

type Array

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

Array is an an array.

Example
o := NewObject()

nodes := []Noder{NewStringDouble("hello")}

t := NewArray(nodes)
k := InheritedKey("foo")
if err := o.Set(k, t); err != nil {
	fmt.Printf("error: %#v\n", err)
}

if err := printer.Fprint(os.Stdout, o.Node()); err != nil {
	fmt.Printf("error: %#v\n", err)
}
Output:

{
  foo: ['hello'],
}

func NewArray

func NewArray(elements []Noder) *Array

NewArray creates an instance of Array.

func (*Array) Node

func (t *Array) Node() ast.Node

Node converts the Array to a jsonnet node.

type Binary

type Binary struct {
	Left  Noder
	Right Noder
	Op    BinaryOp
	Chainer
}

Binary represents a binary operation

Example
o := NewObject()
k := NewKey("foo")
b := NewBinary(NewVar("alpha"), NewVar("beta"), BopPlus)

if err := o.Set(k, b); err != nil {
	fmt.Printf("error: %#v\n", err)
}

if err := printer.Fprint(os.Stdout, o.Node()); err != nil {
	fmt.Printf("error: %#v\n", err)
}
Output:

{
  foo:: alpha + beta,
}

func NewBinary

func NewBinary(left, right Noder, op BinaryOp) *Binary

NewBinary creates an instance of Binary.

func (*Binary) Node

func (b *Binary) Node() ast.Node

Node converts a BinaryOp into an ast node. This will panic if the binary operator is unknown.

type BinaryOp

type BinaryOp string

BinaryOp is a binary operation.

type Boolean

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

Boolean is a boolean.

func NewBoolean

func NewBoolean(value bool) *Boolean

NewBoolean creates an instance of Boolean.

func (*Boolean) Node

func (b *Boolean) Node() ast.Node

Node converts Boolean to a jsonnet node.

type Call

type Call struct {
	Chainer
	// contains filtered or unexported fields
}

Call is a function call.

Example
o := NewObject()
k := NewKey("foo")

c := NewCall("a.b.c.d")

if err := o.Set(k, c); err != nil {
	fmt.Printf("error: %#v\n", err)
}

if err := printer.Fprint(os.Stdout, o.Node()); err != nil {
	fmt.Printf("error: %#v\n", err)
}
Output:

{
  foo:: a.b.c.d,
}

func NewCall

func NewCall(method string) *Call

NewCall creates an instance of Call.

func (*Call) Node

func (c *Call) Node() ast.Node

Node converts the Call to a jsonnet ast node.

func (*Call) SetTarget

func (c *Call) SetTarget(chainable Chainable)

SetTarget sets the target of this Call.

type CallChain

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

CallChain creates a call chain. It allows you to string an arbitrary amount of Chainables together.

func NewCallChain

func NewCallChain(links ...Chainable) *CallChain

NewCallChain creates an instance of CallChain.

func (*CallChain) Node

func (cc *CallChain) Node() ast.Node

Node converts the CallChain to a Jsonnet AST node. nolint: gocyclo

type Chainable

type Chainable interface {
	Chainable()
	Node() ast.Node
}

Chainable is an interface that signifies this object can be used in CallChain.

type Chainer

type Chainer struct{}

Chainer is an extension struct to bring the Chainable function into a type.

func (*Chainer) Chainable

func (c *Chainer) Chainable()

Chainable implements the Chainable interface.

type Conditional

type Conditional struct {
	Cond        Noder
	BranchTrue  Noder
	BranchFalse Noder
	Chainer
}

Conditional represents a conditional

Example
o := NewObject()
k := NewKey("foo")

cond := NewBinary(
	NewVar("alpha"),
	NewVar("beta"),
	BopEqual,
)
trueBranch := NewObject()
trueBranch.Set(
	NewKey(
		"foo",
		KeyOptCategory(ast.ObjectFieldID),
		KeyOptVisibility(ast.ObjectFieldInherit)),
	NewStringDouble("1"),
)

falseBranch := NewObject()
falseBranch.Set(
	NewKey(
		"foo",
		KeyOptCategory(ast.ObjectFieldID),
		KeyOptVisibility(ast.ObjectFieldInherit)),
	NewStringDouble("2"),
)

c := NewConditional(cond, trueBranch, falseBranch)

if err := o.Set(k, c); err != nil {
	fmt.Printf("error: %#v\n", err)
}

if err := printer.Fprint(os.Stdout, o.Node()); err != nil {
	fmt.Printf("error: %#v\n", err)
}
Output:

{
  foo:: if alpha == beta then {
    foo: '1',
  } else {
    foo: '2',
  },
}

func NewConditional

func NewConditional(cond, tbranch, fbranch Noder) *Conditional

NewConditional creates an instance of Conditional.

func (*Conditional) Node

func (c *Conditional) Node() ast.Node

Node converts the Conditional to a jsonnet ast node.

type Function

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

Function is a function.

func NewFunction

func NewFunction(req []string, body Noder) *Function

NewFunction creates an instance of Function.

func (*Function) Node

func (f *Function) Node() ast.Node

Node converts the Function to a jsonnet ast node.

type Import

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

Import is an import declaration.

func NewImport

func NewImport(name string) *Import

NewImport creates an instance of Import.

func (*Import) Node

func (i *Import) Node() ast.Node

Node converts the Import to a jsonnet ast node.

type Index

type Index struct {
	ID     string
	Target Chainable
	Chainer
}

Index is an index type.

func NewIndex

func NewIndex(id string) *Index

NewIndex creates an instance of Index.

func (*Index) Node

func (i *Index) Node() ast.Node

Node converts the Index to a Jsonnet AST node.

func (*Index) SetTarget

func (i *Index) SetTarget(c Chainable)

SetTarget sets the target for this Index.

type Key

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

Key names a fields in an object.

func FunctionKey

func FunctionKey(name string, args []string, opts ...KeyOpt) Key

FunctionKey is a convenience method for creating a function key.

func InheritedKey

func InheritedKey(name string, opts ...KeyOpt) Key

InheritedKey is a convenience method for creating an inherited key.

func LocalKey

func LocalKey(name string, opts ...KeyOpt) Key

LocalKey is a convenience method for creating a local key.

func NewKey

func NewKey(name string, opts ...KeyOpt) Key

NewKey creates an instance of Key. KeyOpt functional options can be used to configure the newly generated key.

func (*Key) Method

func (k *Key) Method() *ast.Function

Method returns the jsonnet AST object file method parameter.

func (Key) Mixin

func (k Key) Mixin() bool

Mixin returns true if the jsonnet object should be super sugared.

type KeyOpt

type KeyOpt func(k *Key)

KeyOpt is a functional option for configuring Key.

func KeyOptCategory

func KeyOptCategory(kc ast.ObjectFieldKind) KeyOpt

KeyOptCategory is a functional option for setting key category

func KeyOptComment

func KeyOptComment(text string) KeyOpt

KeyOptComment is a functional option for setting a comment on a key

func KeyOptMixin

func KeyOptMixin(b bool) KeyOpt

KeyOptMixin is a functional option for setting this key as a mixin

func KeyOptNamedParams

func KeyOptNamedParams(params ...OptionalArg) KeyOpt

KeyOptNamedParams is a functional option for setting named params for a key.

func KeyOptParams

func KeyOptParams(params []string) KeyOpt

KeyOptParams is functional option for setting params for a key. If there are no required parameters, pass an empty []string.

func KeyOptVisibility

func KeyOptVisibility(kv ast.ObjectFieldHide) KeyOpt

KeyOptVisibility is a functional option for setting key visibility

type Local

type Local struct {
	Body Noder
	// contains filtered or unexported fields
}

Local is a local declaration.

func NewLocal

func NewLocal(name string, value, body Noder) *Local

NewLocal creates an instance of Local.

func (*Local) Node

func (l *Local) Node() ast.Node

Node converts the Local to a jsonnet ast node.

type Noder

type Noder interface {
	Node() ast.Node
}

Noder is an entity that can be converted to a jsonnet node.

func Combine

func Combine(nodes ...Noder) Noder

Combine combines multiple nodes into a single node. If one argument is passed, it is returned. If two or more arguments are passed, they are combined using a Binary.

func ValueToNoder

func ValueToNoder(v interface{}) (Noder, error)

ValueToNoder converts a value to a Noder.

type Number

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

Number is an a number.

func NewFloat

func NewFloat(f float64) *Number

NewFloat creates a float instance of a number.

func NewInt

func NewInt(i int) *Number

NewInt creates an integer number.

func (*Number) Node

func (t *Number) Node() ast.Node

Node converts the Number to a jsonnet node.

type Object

type Object struct {
	Oneline bool
	// contains filtered or unexported fields
}

Object is an item that can have multiple keys with values.

Example
o := NewObject()

k := NewKey("foo")
o2 := NewObject()

if err := o.Set(k, o2); err != nil {
	fmt.Printf("error: %#v\n", err)
}

if err := printer.Fprint(os.Stdout, o.Node()); err != nil {
	fmt.Printf("error: %#v\n", err)
}
Output:

{
  foo:: {},
}

func KVFromMap

func KVFromMap(m map[string]interface{}) (*Object, error)

KVFromMap creates a object using a map.

func NewObject

func NewObject(opts ...ObjectOpt) *Object

NewObject creates an Object. ObjectOpt functional arguments can be used to configure the newly generated key.

func OnelineObject

func OnelineObject(opts ...ObjectOpt) *Object

OnelineObject is a convenience method for creating a online object.

func (*Object) Get

func (o *Object) Get(keyName string) Noder

Get retrieves a field by name.

func (*Object) Keys

func (o *Object) Keys() []Key

Keys returns a slice of keys in the object.

func (*Object) Node

func (o *Object) Node() ast.Node

Node converts the object to a jsonnet node.

func (*Object) Set

func (o *Object) Set(key Key, value Noder) error

Set sets a field with a value.

type ObjectOpt

type ObjectOpt func(*Object)

ObjectOpt is a functional option for Object.

func ObjectOptOneline

func ObjectOptOneline(oneline bool) ObjectOpt

ObjectOptOneline is a functional option which sets the object's oneline status.

type OptionalArg

type OptionalArg struct {
	Name    string
	Default Noder
}

OptionalArg is an optional argument.

func (*OptionalArg) NamedArgument

func (oa *OptionalArg) NamedArgument() ast.NamedArgument

NamedArgument converts the OptionalArgument to a jsonnet NamedArgument.

func (*OptionalArg) NamedParameter

func (oa *OptionalArg) NamedParameter() ast.NamedParameter

NamedParameter converts the OptionalArgument to a jsonnet NamedParameter.

type Self

type Self struct{}

Self represents self.

func (*Self) Node

func (s *Self) Node() ast.Node

Node converts self to a jsonnet self node.

type StringDouble

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

StringDouble is double quoted string.

func NewStringDouble

func NewStringDouble(text string) *StringDouble

NewStringDouble creates an instance of StringDouble.

func (*StringDouble) Node

func (t *StringDouble) Node() ast.Node

Node converts the StringDouble to a jsonnet node.

type Targetable

type Targetable interface {
	Chainable
	SetTarget(Chainable)
}

Targetable is a Chainable that allows you to set a target. Can be used with Calls, Indexes, and Applies.

type Var

type Var struct {
	ID string
	Chainer
}

Var represents a variable.

func NewVar

func NewVar(id string) *Var

NewVar creates an instance of Var.

func (*Var) Node

func (v *Var) Node() ast.Node

Node converts the var to a jsonnet ast node.

Jump to

Keyboard shortcuts

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