Documentation ¶
Overview ¶
Package yaml can marshal and unmarshal cty values in YAML format.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var YAMLDecodeFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "src", Type: cty.String, }, }, Type: func(args []cty.Value) (cty.Type, error) { if !args[0].IsKnown() { return cty.DynamicPseudoType, nil } if args[0].IsNull() { return cty.NilType, function.NewArgErrorf(0, "YAML source code cannot be null") } return Standard.ImpliedType([]byte(args[0].AsString())) }, Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { return Standard.Unmarshal([]byte(args[0].AsString()), retType) }, })
YAMLDecodeFunc is a cty function for decoding arbitrary YAML source code into a cty Value, using the ImpliedType and Unmarshal methods of the Standard pre-defined converter.
var YAMLEncodeFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "value", Type: cty.DynamicPseudoType, AllowNull: true, AllowDynamicType: true, }, }, Type: function.StaticReturnType(cty.String), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { if !args[0].IsWhollyKnown() { return cty.UnknownVal(retType), nil } raw, err := Standard.Marshal(args[0]) if err != nil { return cty.NilVal, err } return cty.StringVal(string(raw)), nil }, })
YAMLEncodeFunc is a cty function for encoding an arbitrary cty value into YAML.
Functions ¶
func ImpliedType ¶
ImpliedType analyzes the given source code and returns a suitable type that it could be decoded into.
For a converter that is using standard YAML rather than cty-specific custom tags, only a subset of cty types can be produced: strings, numbers, bools, tuple types, and object types.
This is an alias for ImpliedType on the predefined Converter in "Standard".
func Marshal ¶
Marshal serializes the given value into a YAML document, using a fixed mapping from cty types to YAML constructs.
This is an alias for Marshal on the predefined Converter in "Standard".
Note that unlike the function of the same name in the cty JSON package, this does not take a type constraint and therefore the YAML serialization cannot preserve late-bound type information in the serialization to be recovered from Unmarshal. Instead, any cty.DynamicPseudoType in the type constraint given to Unmarshal will be decoded as if the corresponding portion of the input were processed with ImpliedType to find a target type.
func Unmarshal ¶
Unmarshal reads the document found within the given source buffer and attempts to convert it into a value conforming to the given type constraint.
This is an alias for Unmarshal on the predefined Converter in "Standard".
An error is returned if the given source contains any YAML document delimiters.
Types ¶
type Converter ¶
type Converter struct {
// contains filtered or unexported fields
}
A Converter can marshal and unmarshal between cty values and YAML bytes.
Because there are many different ways to map cty to YAML and vice-versa, a converter is configurable using the settings in ConverterConfig, which allow for a few different permutations of mapping to YAML.
If you are just trying to work with generic, standard YAML, the predefined converter in Standard should be good enough.
var Standard *Converter = NewConverter(&ConverterConfig{})
Standard is a predefined Converter that produces and consumes generic YAML using only built-in constructs that any other YAML implementation ought to understand.
func NewConverter ¶
func NewConverter(config *ConverterConfig) *Converter
NewConverter creates a new Converter with the given configuration.
func (*Converter) ImpliedType ¶
ImpliedType analyzes the given source code and returns a suitable type that it could be decoded into.
For a converter that is using standard YAML rather than cty-specific custom tags, only a subset of cty types can be produced: strings, numbers, bools, tuple types, and object types.
func (*Converter) Marshal ¶
Marshal serializes the given value into a YAML document, using a fixed mapping from cty types to YAML constructs.
Note that unlike the function of the same name in the cty JSON package, this does not take a type constraint and therefore the YAML serialization cannot preserve late-bound type information in the serialization to be recovered from Unmarshal. Instead, any cty.DynamicPseudoType in the type constraint given to Unmarshal will be decoded as if the corresponding portion of the input were processed with ImpliedType to find a target type.
type ConverterConfig ¶
type ConverterConfig struct { // EncodeAsFlow, when set to true, causes Marshal to produce flow-style // mapping and sequence serializations. EncodeAsFlow bool }
ConverterConfig is used to configure a new converter, using NewConverter.
type Error ¶
type Error struct {
Line, Column int
// contains filtered or unexported fields
}
Error is an error implementation used to report errors that correspond to a particular position in an input buffer.
func (Error) Cause ¶
Cause is an implementation of the interface used by github.com/pkg/errors.Cause, returning the underlying error without the position information.
func (Error) WrappedErrors ¶
WrappedErrors is an implementation of github.com/hashicorp/errwrap.Wrapper returning the underlying error without the position information.