Documentation
¶
Overview ¶
Package yaml mirrors the repository's JSON helper shape for YAML data.
The package converts YAML input to JSON before delegating to the JSON helpers, which keeps one implementation of the fast, non-reflective JSON decoding paths and their context-aware stream handling. On the write path, it encodes to JSON first, then converts that JSON to YAML.
YAML parsing support comes from sigs.k8s.io/yaml, which uses yaml/go-yaml underneath. In practice that means the package supports most of YAML 1.2 while preserving some YAML 1.1 behaviour for compatibility, including YAML aliases and anchors, as documented at https://github.com/yaml/go-yaml#compatibility.
Index ¶
- Variables
- func IsYAMLFile(extension string) bool
- func Marshal(v any) ([]byte, error)
- func MarshalWithContext(ctx context.Context, v any) (content []byte, err error)
- func ToJSON(yaml []byte) (json []byte, err error)
- func Unmarshal(data []byte, v any) error
- func UnmarshallWithContext(ctx context.Context, data []byte, v any) error
- type Decoder
- type Encoder
Constants ¶
This section is empty.
Variables ¶
var ( // YAMLExtensions is the list of file extensions that are considered YAML files. YAMLExtensions = []string{".yaml", ".yml"} )
Functions ¶
func IsYAMLFile ¶ added in v1.159.0
IsYAMLFile returns true if the given extension is a YAML file extension.
func Marshal ¶
Marshal encodes a value to a YAML byte slice. It follows the same helper shape as the repository's JSON `Marshal` helper.
Values are first encoded through the JSON helpers so any generated fast JSON serialisers can still be used, then the resulting JSON is converted to YAML.
func MarshalWithContext ¶
MarshalWithContext encodes a value to a YAML byte slice using a context-aware Encoder. It follows the same helper shape as Marshal, but routes the write through the package's context-aware streaming helpers.
func ToJSON ¶
ToJSON converts YAML data to JSON.
YAML parsing support comes from sigs.k8s.io/yaml, which uses yaml/go-yaml underneath. In practice that means it supports most of YAML 1.2 while preserving some YAML 1.1 behaviour for compatibility, as documented at https://github.com/yaml/go-yaml#compatibility. That includes support for YAML aliases and anchors. See also https://github.com/yaml/go-yaml.
func Unmarshal ¶
Unmarshal decodes a YAML byte slice into a destination value. It follows the same helper shape as the repository's JSON `Unmarshal` helper.
YAML is converted to JSON first, so the JSON helpers can retain their fast- generated decoding paths and shared decoding behaviour.
func UnmarshallWithContext ¶
UnmarshallWithContext decodes a YAML byte slice into a destination value using a context-aware Decoder. It follows the same helper shape as Unmarshal, but routes the read through the package's context-aware streaming helpers.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder reads YAML from a reader and decodes it into Go values. It follows the same helper shape as the repository's JSON `Decoder`.
Reads are context-aware, and the input is converted to JSON before the JSON helpers are used, so the repository keeps a single fast decoding path. This should not be used by more than one goroutine at a time.
func NewDecoder ¶
NewDecoder creates a Decoder that reads YAML values from r. It follows the same helper shape as the repository's JSON `NewDecoder` helper.
func (*Decoder) Decode ¶
Decode reads YAML from the decoder and stores the result in v. It follows the same helper shape as the repository's JSON `Decoder.Decode` method.
The data is converted to JSON first, then passed to the JSON helpers, so the same fast and implementation-agnostic decoding logic is reused here.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder writes YAML values to a writer. It follows the same helper shape as the repository's JSON `Encoder`.
Writes are context-aware. Values are first encoded through the JSON helpers so any generated fast JSON serialisers can still be used before converting the JSON output to YAML. This should not be used by more than one goroutine at a time.
func NewEncoder ¶
NewEncoder creates an Encoder that writes YAML values to w. It follows the same helper shape as the repository's JSON `NewEncoder` helper.