yaml

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package yaml provides generic YAML read and write operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v any) ([]byte, error)

Marshal converts a value to formatted YAML.

func Read

func Read[T any](path string) (*T, error)

Read reads a YAML file and unmarshals it into a value of type T.

func Unmarshal

func Unmarshal[T any](data []byte) (*T, error)

Unmarshal parses YAML data into a value of type T.

func Write

func Write(path string, v any) error

Write marshals a value to YAML, formats it with yamlfmt, adds a copyright header and writes it to a file.

Types

type RefString

type RefString string

RefString is a string that is a reference to another resource.

func (RefString) MarshalYAML

func (r RefString) MarshalYAML() (any, error)

MarshalYAML implements the yaml.Marshaler interface.

func (*RefString) UnmarshalYAML

func (r *RefString) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type StringSlice

type StringSlice []string

StringSlice is a custom slice of strings that allows for fine-grained control over YAML marshaling when used with the 'omitempty' tag.

By implementing the yaml.IsZeroer interface, it ensures that:

  1. A nil slice is considered "zero" and is omitted from the output.
  2. An empty but initialized slice (e.g., []string{}) is NOT considered "zero" and is explicitly marshaled as an empty YAML sequence ([]).

func (StringSlice) IsZero

func (s StringSlice) IsZero() bool

IsZero implements the yaml.IsZeroer interface, which determines whether a field should be considered "empty" when the 'omitempty' struct tag is used.

Jump to

Keyboard shortcuts

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