Documentation
¶
Overview ¶
Package builder exposes an API to create an Alloy configuration file by constructing a set of tokens.
Index ¶
- type Block
- type Body
- func (b *Body) AppendBlock(block *Block)
- func (b *Body) AppendFrom(goValue interface{})
- func (b *Body) AppendTokens(tokens []Token)
- func (b *Body) Nodes() []tokenNode
- func (b *Body) SetAttributeTokens(name string, tokens []Token)
- func (b *Body) SetAttributeValue(name string, goValue interface{})
- func (b *Body) SetValueOverrideHook(valueOverrideHook ValueOverrideHook)
- func (b *Body) Tokens() []Token
- type Expr
- type File
- type Token
- type Tokenizer
- type ValueOverrideHook
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
A Block encapsulates a body within a named and labeled Alloy block. Blocks must be created by calling NewBlock, but its public struct fields may be safely modified by callers.
type Body ¶
type Body struct {
// contains filtered or unexported fields
}
Body is a list of block and attribute statements. A Body cannot be manually created, but is retrieved from a File or Block.
func (*Body) AppendBlock ¶
AppendBlock adds a new block inside of the Body.
func (*Body) AppendFrom ¶
func (b *Body) AppendFrom(goValue interface{})
AppendFrom sets attributes and appends blocks defined by goValue into the Body. If any value reachable from goValue implements Tokenizer, the printed tokens will instead be retrieved by calling the AlloyTokenize method.
Optional attributes and blocks set to default values are trimmed. If goValue implements Defaulter, default values are retrieved by calling SetToDefault against a copy. Otherwise, default values are the zero value of the respective Go types.
goValue must be a struct or a pointer to a struct that contains alloy struct tags.
func (*Body) AppendTokens ¶
AppendTokens appends raw tokens to the Body.
func (*Body) SetAttributeTokens ¶
SetAttributeTokens sets an attribute to the Body whose value is a set of raw tokens. If the attribute was previously set, its value tokens are updated.
Attributes will be written out in the order they were initially created.
func (*Body) SetAttributeValue ¶
SetAttributeValue sets an attribute in the Body whose value is converted from a Go value to an Alloy value. The Go value is encoded using the normal Go to Alloy encoding rules. If any value reachable from goValue implements Tokenizer, the printed tokens will instead be retrieved by calling the AlloyTokenize method.
If the attribute was previously set, its value tokens are updated.
Attributes will be written out in the order they were initially crated.
func (*Body) SetValueOverrideHook ¶
func (b *Body) SetValueOverrideHook(valueOverrideHook ValueOverrideHook)
SetValueOverrideHook sets a hook to override the value that will be token encoded. The hook can mutate the value to be encoded or should return it unmodified. This hook can be skipped by leaving it nil or setting it to nil.
type Expr ¶
type Expr struct {
// contains filtered or unexported fields
}
An Expr represents a single Alloy expression.
func (*Expr) SetValue ¶
func (e *Expr) SetValue(goValue interface{})
SetValue sets the Expr to an Alloy value converted from a Go value. The Go value is encoded using the normal Go to Alloy encoding rules. If any value reachable from goValue implements Tokenizer, the printed tokens will instead be retrieved by calling the AlloyTokenize method.
type File ¶
type File struct {
// contains filtered or unexported fields
}
A File represents an Alloy configuration file.
type Token ¶
A Token is a wrapper around token.Token which contains the token type alongside its literal. Use LiteralTok as the Tok field to write literal characters such as whitespace.
type Tokenizer ¶
type Tokenizer interface { // AlloyTokenize returns the raw set of Alloy tokens which are used when // printing out the value with syntax/token/builder. AlloyTokenize() []Token }
Tokenizer is any value which can return a raw set of tokens.
type ValueOverrideHook ¶
type ValueOverrideHook = func(val interface{}) interface{}