hcl

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

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 added in v0.10.2

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 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.

Types

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

type Unmarshaler interface {
	UnmarshalHCL(cty.Value) error
}

Unmarshaler unmarshals a value from cty.Value.

Directories

Path Synopsis
ext

Jump to

Keyboard shortcuts

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