unmarshal

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package unmarshal provides YAML decoding helpers for flexible input formats.

Supports parsing strings as structs, single values as slices, and templated fields with deferred decoding. Built on go-yaml with strict decoding rules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode added in v0.0.13

func Decode(node ast.Node, out any) error

Decode decodes a YAML node into the specified output type, disallowing unknown fields.

func Lax added in v0.0.13

func Lax(data []byte, out any, options ...yaml.DecodeOption) error

Lax unmarshals YAML data into the specified output type, allowing unknown fields.

func SingleOrSlice

func SingleOrSlice[T any](node ast.Node) ([]T, error)

SingleOrSlice unmarshals YAML data into a slice of type T. Handles both single values and sequences by wrapping scalars/mappings.

func SingleStringOrStruct added in v0.0.13

func SingleStringOrStruct[T any](node ast.Node, out *T) error

SingleStringOrStruct handles either a string value or a full struct decoding.

func Strict added in v0.0.13

func Strict(data []byte, out any, options ...yaml.DecodeOption) error

Strict unmarshals YAML data into the specified output type, disallowing unknown fields.

Types

type SingleOrSliceType added in v0.0.1

type SingleOrSliceType[T any] []T

SingleOrSliceType represents a flexible YAML unmarshaling target. Implements custom unmarshaling to handle both single values and slices of values in YAML input. Works with any comparable type T.

func (*SingleOrSliceType[T]) UnmarshalYAML added in v0.0.1

func (ss *SingleOrSliceType[T]) UnmarshalYAML(node ast.Node) (err error)

UnmarshalYAML implements yaml.NodeUnmarshaler for SingleOrSliceType. Calls SingleOrSlice to do the actual decoding.

type Templatable added in v0.0.13

type Templatable[T any] struct {
	// The parsed value of type T.
	Value T
	// The template string to be parsed.
	Template string
	// contains filtered or unexported fields
}

Templatable wraps a string-based template and its parsed value of type T. Used to delay parsing of the value until explicitly needed.

func (*Templatable[T]) Get added in v0.0.13

func (t *Templatable[T]) Get() (T, error)

Get returns the parsed value. Does not trigger parsing.

func (*Templatable[T]) IsUnset added in v0.0.13

func (t *Templatable[T]) IsUnset() bool

IsUnset returns true if the Template is empty.

func (Templatable[T]) MarshalYAML added in v0.0.13

func (t Templatable[T]) MarshalYAML() (any, error)

MarshalYAML returns the Template string for YAML serialization.

TODO(Idelchi): Return t.Template or t.Value?

func (*Templatable[T]) Parse added in v0.0.13

func (t *Templatable[T]) Parse() error

Parse attempts to unmarshal the Template string into Value.

func (*Templatable[T]) Set added in v0.0.13

func (t *Templatable[T]) Set(s string)

Set assigns a new value to Template.

func (*Templatable[T]) UnmarshalYAML added in v0.0.13

func (t *Templatable[T]) UnmarshalYAML(node ast.Node) error

UnmarshalYAML decodes the raw YAML node into the Template string. Does not parse the value; use Parse separately for that.

Jump to

Keyboard shortcuts

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