yaml

package
v2.714.0 Latest Latest
Warning

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

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

Documentation

Overview

Package yaml provides a streaming YAML github.com/alexfalkowski/go-service/v2/encoding/stream.Encoder/ github.com/alexfalkowski/go-service/v2/encoding/stream.Decoder pair used by go-service.

It wraps go.yaml.in/yaml/v3's own NewEncoder/NewDecoder types, which are each bound to one writer/reader for many Encode/Decode calls. It carries over the strict decoding policy of github.com/alexfalkowski/go-service/v2/encoding/yaml (unknown fields rejected), but drops that package's trailing-document rejection, since a stream is expected to contain many documents. Encoder is a direct alias of the upstream type, so its Close is not idempotent — a second call surfaces upstream's "expected nothing after STREAM-END" error; callers must call Close exactly once, at the true end of the stream, per github.com/alexfalkowski/go-service/v2/encoding/stream.Encoder's contract. See NewEncoder.

Start with the package-level constructors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	*yaml.Decoder
}

Decoder streams YAML values from a reader bound at construction.

Decoder embeds the go.yaml.in/yaml/v3.Decoder, so [Decoder.Decode] is the embedded decoder's own method. Decoder satisfies github.com/alexfalkowski/go-service/v2/encoding/stream.Decoder structurally, without this package importing that package: the underlying decoder has no Close method at all, so this thin wrapper exists only to add one.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder constructs a streaming YAML Decoder bound to r.

Unlike github.com/alexfalkowski/go-service/v2/encoding/yaml.Encoder's Decode, the returned decoder allows additional YAML documents after the first: it does not enforce single-value trailing-data rejection, since a stream is expected to carry many documents. Unknown fields remain rejected.

func (*Decoder) Close

func (d *Decoder) Close() error

Close is a no-op: go.yaml.in/yaml/v3's Decoder has no Close method or finalization state.

type Encoder

type Encoder = yaml.Encoder

Encoder is an alias of go.yaml.in/yaml/v3.Encoder.

Encoder already satisfies github.com/alexfalkowski/go-service/v2/encoding/stream.Encoder structurally (Encode and Close), so no wrapper type is needed.

Note: the underlying Close is not idempotent — a second call returns "yaml: expected nothing after STREAM-END". Callers must call Close exactly once, at the end of the stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder constructs a streaming YAML Encoder bound to w.

The underlying encoder separates successive documents with "---" and only finalizes the stream once Close is called.

Jump to

Keyboard shortcuts

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