Documentation ¶
Index ¶
- func Decode(ctx *hcl.EvalContext, body hcl.Body, val any) hcl.Diagnostics
- func DecodeBlock(ctx *hcl.EvalContext, block *hcl.Block, val any) hcl.Diagnostics
- func DecodeExpression(ctx *hcl.EvalContext, expr hcl.Expression, val any) hcl.Diagnostics
- func Encode(val any, block *Block) hcl.Diagnostics
- func EncodeBlock(val any, block *Block, typeName string, labels []string) hcl.Diagnostics
- func ParseFile(path string, subject *hcl.Range) (hcl.Body, hcl.Diagnostics)
- func ParseFiles(paths []string, subject *hcl.Range) (hcl.Body, hcl.Diagnostics)
- func ParseSource(name string, src []byte) (hcl.Body, hcl.Diagnostics)
- func ParseSources(srcs [][]byte) (hcl.Body, hcl.Diagnostics)
- type Attribute
- type Block
- type Marshaler
- type OnEncodeBlock
- type PostDecodeAttribute
- type PostDecodeBlock
- type PreDecodeAttribute
- type PreDecodeBlock
- type Unmarshaler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
func Decode(ctx *hcl.EvalContext, body hcl.Body, val any) hcl.Diagnostics
Decode decodes the given HCL body into the given value. The value must be a pointer to a struct.
It works similar to the Decode function from the gohcl package, but it has improved support for decoding values into maps and slices. It also supports encoding.TextUnmarshaler interface and additional Unmarshaler interface that allows to decode values into custom types directly from cty.Value.
Only fields with the "hcl" tag will be decoded. The tag contains the name of the attribute or block and additional options separated by comma.
Supported options are
- attr - the field is an attribute, it will be decoded from the HCL body attributes. It is the default tag and can be omitted.
- label - a label of the parent block. Multiple labels can be defined.
- optional - the field is optional, if it is not present in the HCL body, the field will be left as zero value.
- ignore - the field will be ignored but still be a part of the schema.
- block - the field is a block, it will be decoded from the HCL blocks. The field must be a struct, slice of structs or a map of structs.
- remain - the field is populated with the remaining HCL body. The field must be hcl.Body.
- body - the field is populated with the HCL body. The field must be hcl.BodyContent.
- content - the field is populated with the HCL body content. The field must be hcl.BodyContent.
- schema - the field is populated with the HCL body schema. The field must be hcl.BodySchema.
- range - the block range. The field must be hcl.Range.
If name is omitted, the field name will be used.
func DecodeBlock ¶
func DecodeBlock(ctx *hcl.EvalContext, block *hcl.Block, val any) hcl.Diagnostics
DecodeBlock decodes the given HCL block into the given value.
func DecodeExpression ¶
func DecodeExpression(ctx *hcl.EvalContext, expr hcl.Expression, val any) hcl.Diagnostics
DecodeExpression decodes the given HCL expression into the given value.
func EncodeBlock ¶
EncodeBlock encodes a struct to HCL block and appends it to the given block. The value must be a struct.
The typeName argument specifies the block type name. Labels are specified using the labels argument. If labels is nil, labels are read from the struct tags.
func ParseFile ¶
func ParseFile(path string, subject *hcl.Range) (hcl.Body, hcl.Diagnostics)
ParseFile parses the given path into a hcl.File. The subject argument is optional. It is used to provide a range for the returned diagnostics.
func ParseFiles ¶
func ParseFiles(paths []string, subject *hcl.Range) (hcl.Body, hcl.Diagnostics)
ParseFiles parses the HCL configuration files at the given paths. It returns a merged hcl.Body. The subject argument is optional. It is used to provide a range for the returned diagnostics.
func ParseSource ¶
ParseSource parses the given source into a hcl.File.
func ParseSources ¶
func ParseSources(srcs [][]byte) (hcl.Body, hcl.Diagnostics)
ParseSources parses the HCL configuration sources. It returns a merged hcl.Body.
Types ¶
type Attribute ¶
Attribute represents a single attribute in a HCL block.
It is used to build am HCL configuration.
type Block ¶
Block represents a single HCL block.
If typeName is empty, the block is a root block.
It is used to build an HCL configuration.
func (*Block) AppendAttribute ¶
AppendAttribute appends a new attribute to the given block.
func (*Block) AppendBlock ¶
AppendBlock appends a new block to the given block.
type Marshaler ¶
Marshaler is the interface implemented by types that can marshal themselves into a cty.Value representation.
type OnEncodeBlock ¶
type OnEncodeBlock interface {
OnEncodeBlock(block *Block) hcl.Diagnostics
}
OnEncodeBlock is called during encoding of a struct to HCL.
type PostDecodeAttribute ¶
type PostDecodeAttribute interface {
PostDecodeAttribute(*hcl.EvalContext, *hcl.Attribute) hcl.Diagnostics
}
PostDecodeAttribute is called after an attribute is decoded.
type PostDecodeBlock ¶
type PostDecodeBlock interface {
PostDecodeBlock(*hcl.EvalContext, *hcl.BodySchema, *hcl.Block, *hcl.BodyContent) hcl.Diagnostics
}
PostDecodeBlock is called after a block is decoded.
type PreDecodeAttribute ¶
type PreDecodeAttribute interface {
PreDecodeAttribute(*hcl.EvalContext, *hcl.Attribute) hcl.Diagnostics
}
PreDecodeAttribute is called before an attribute is decoded.
type PreDecodeBlock ¶
type PreDecodeBlock interface {
PreDecodeBlock(*hcl.EvalContext, *hcl.BodySchema, *hcl.Block, *hcl.BodyContent) hcl.Diagnostics
}
PreDecodeBlock is called before a block is decoded.
type Unmarshaler ¶
Unmarshaler is the interface implemented by types that can unmarshal a cty.Value representation of themselves.