Documentation ¶
Index ¶
- Constants
- type Apply
- type Array
- type Binary
- type BinaryOp
- type Boolean
- type Call
- type CallChain
- type Chainable
- type Chainer
- type Conditional
- type Function
- type Import
- type Index
- type Key
- type KeyOpt
- type Local
- type Noder
- type Number
- type Object
- type ObjectOpt
- type OptionalArg
- type Self
- type StringDouble
- type Targetable
- type Var
Examples ¶
Constants ¶
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"), }
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"], }
type Binary ¶
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, }
type Boolean ¶
type Boolean struct {
// contains filtered or unexported fields
}
Boolean is a boolean.
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, }
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 ¶
NewCallChain creates an instance of CallChain.
type Chainer ¶
type Chainer struct{}
Chainer is an extension struct to bring the Chainable function into a type.
type Conditional ¶
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 ¶
NewFunction creates an instance of Function.
type Import ¶
type Import struct {
// contains filtered or unexported fields
}
Import is an import declaration.
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key names a fields in an object.
func FunctionKey ¶
FunctionKey is a convenience method for creating a function key.
func InheritedKey ¶
InheritedKey is a convenience method for creating an inherited key.
func NewKey ¶
NewKey creates an instance of Key. KeyOpt functional options can be used to configure the newly generated key.
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 ¶
KeyOptComment is a functional option for setting a comment on a key
func KeyOptMixin ¶
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 ¶
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.
type Noder ¶
Noder is an entity that can be converted to a jsonnet node.
func Combine ¶
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 ¶
ValueToNoder converts a value to a Noder.
type Number ¶
type Number struct {
// contains filtered or unexported fields
}
Number is an a number.
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 NewObject ¶
NewObject creates an Object. ObjectOpt functional arguments can be used to configure the newly generated key.
func OnelineObject ¶
OnelineObject is a convenience method for creating a online object.
type ObjectOpt ¶
type ObjectOpt func(*Object)
ObjectOpt is a functional option for Object.
func ObjectOptOneline ¶
ObjectOptOneline is a functional option which sets the object's oneline status.
type OptionalArg ¶
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 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 ¶
Targetable is a Chainable that allows you to set a target. Can be used with Calls, Indexes, and Applies.