2017-09-11 23:56:31 +00:00
|
|
|
// Package gohcl allows decoding HCL configurations into Go data structures.
|
2017-05-20 23:46:54 +00:00
|
|
|
//
|
|
|
|
// It provides a convenient and concise way of describing the schema for
|
|
|
|
// configuration and then accessing the resulting data via native Go
|
|
|
|
// types.
|
|
|
|
//
|
|
|
|
// A struct field tag scheme is used, similar to other decoding and
|
|
|
|
// unmarshalling libraries. The tags are formatted as in the following example:
|
|
|
|
//
|
2017-09-12 00:29:56 +00:00
|
|
|
// ThingType string `hcl:"thing_type,attr"`
|
2017-05-20 23:46:54 +00:00
|
|
|
//
|
|
|
|
// Within each tag there are two comma-separated tokens. The first is the
|
|
|
|
// name of the corresponding construct in configuration, while the second
|
|
|
|
// is a keyword giving the kind of construct expected. The following
|
|
|
|
// kind keywords are supported:
|
|
|
|
//
|
|
|
|
// attr (the default) indicates that the value is to be populated from an attribute
|
|
|
|
// block indicates that the value is to populated from a block
|
|
|
|
// label indicates that the value is to populated from a block label
|
2020-02-14 02:51:40 +00:00
|
|
|
// optional is the same as attr, but the field is optional
|
2017-05-20 23:46:54 +00:00
|
|
|
// remain indicates that the value is to be populated from the remaining body after populating other fields
|
|
|
|
//
|
2017-09-11 23:40:37 +00:00
|
|
|
// "attr" fields may either be of type *hcl.Expression, in which case the raw
|
2017-05-20 23:46:54 +00:00
|
|
|
// expression is assigned, or of any type accepted by gocty, in which case
|
|
|
|
// gocty will be used to assign the value to a native Go type.
|
|
|
|
//
|
2017-09-11 23:40:37 +00:00
|
|
|
// "block" fields may be of type *hcl.Block or hcl.Body, in which case the
|
2017-05-20 23:46:54 +00:00
|
|
|
// corresponding raw value is assigned, or may be a struct that recursively
|
|
|
|
// uses the same tags. Block fields may also be slices of any of these types,
|
|
|
|
// in which case multiple blocks of the corresponding type are decoded into
|
|
|
|
// the slice.
|
|
|
|
//
|
2020-10-22 23:53:37 +00:00
|
|
|
// "body" can be placed on a single field of type hcl.Body to capture
|
|
|
|
// the full hcl.Body that was decoded for a block. This does not allow leftover
|
|
|
|
// values like "remain", so a decoding error will still be returned if leftover
|
|
|
|
// fields are given. If you want to capture the decoding body PLUS leftover
|
|
|
|
// fields, you must specify a "remain" field as well to prevent errors. The
|
|
|
|
// body field and the remain field will both contain the leftover fields.
|
|
|
|
//
|
2017-05-20 23:46:54 +00:00
|
|
|
// "label" fields are considered only in a struct used as the type of a field
|
|
|
|
// marked as "block", and are used sequentially to capture the labels of
|
|
|
|
// the blocks being decoded. In this case, the name token is used only as
|
|
|
|
// an identifier for the label in diagnostic messages.
|
|
|
|
//
|
2020-02-14 02:51:40 +00:00
|
|
|
// "optional" fields behave like "attr" fields, but they are optional
|
|
|
|
// and will not give parsing errors if they are missing.
|
|
|
|
//
|
2017-05-20 23:46:54 +00:00
|
|
|
// "remain" can be placed on a single field that may be either of type
|
2017-09-11 23:40:37 +00:00
|
|
|
// hcl.Body or hcl.Attributes, in which case any remaining body content is
|
2017-05-20 23:46:54 +00:00
|
|
|
// placed into this field for delayed processing. If no "remain" field is
|
|
|
|
// present then any attributes or blocks not matched by another valid tag
|
|
|
|
// will cause an error diagnostic.
|
|
|
|
//
|
2018-11-04 01:16:51 +00:00
|
|
|
// Only a subset of this tagging/typing vocabulary is supported for the
|
|
|
|
// "Encode" family of functions. See the EncodeIntoBody docs for full details
|
|
|
|
// on the constraints there.
|
|
|
|
//
|
2017-05-20 23:46:54 +00:00
|
|
|
// Broadly-speaking this package deals with two types of error. The first is
|
|
|
|
// errors in the configuration itself, which are returned as diagnostics
|
|
|
|
// written with the configuration author as the target audience. The second
|
|
|
|
// is bugs in the calling program, such as invalid struct tags, which are
|
|
|
|
// surfaced via panics since there can be no useful runtime handling of such
|
|
|
|
// errors and they should certainly not be returned to the user as diagnostics.
|
2017-09-11 23:00:31 +00:00
|
|
|
package gohcl
|