yaml

package
v1.6.6 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NewEncoder = yaml.NewEncoder
	NewDecoder = yaml.NewDecoder
)

NewEncoder 和 NewDecoder 是 go.yaml.in/yaml/v3 对应函数的别名,用于面向 io.Writer 和 io.Reader 的流式多文档编解码;Encoder 使用后必须调用 Close,否则剩余数据不会写入 Writer。

Functions

func Marshal

func Marshal[T codec.Data](in any, opts ...Options) (T, error)

func MustMarshal

func MustMarshal[T codec.Data](in any, opts ...Options) T

func MustUnmarshal

func MustUnmarshal[V any, T codec.Data](in T, opts ...Options) (v V)

func Unmarshal

func Unmarshal[T codec.Data](in T, out any, opts ...Options) error

Types

type Options added in v1.6.2

type Options func(*options)

Options 配置编解码行为,后面的同名选项覆盖前面的选项;不适用于当前方向的选项被忽略。

func WithCompactSeqIndent added in v1.6.2

func WithCompactSeqIndent(enabled bool) Options

WithCompactSeqIndent 仅序列化生效:控制序列标记 "- " 是否计入缩进,默认关闭。

func WithIndent added in v1.6.2

func WithIndent(spaces int) Options

WithIndent 仅序列化生效:设置缩进空格数,0 使用上游默认值,负数在序列化时触发 panic。

func WithKnownFields added in v1.6.2

func WithKnownFields(enabled bool) Options

WithKnownFields 仅反序列化生效:检查映射键是否对应目标结构体字段,默认关闭,不限制 map 的键。

Jump to

Keyboard shortcuts

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