gotools/cmd/yamltool/encode.go

17 lines
305 B
Go
Raw Permalink Normal View History

2025-01-07 08:27:12 +00:00
package main
import (
"github.com/goccy/go-yaml"
"io"
"os"
)
func encode(writer io.Writer, data any) error {
enc := yaml.NewEncoder(os.Stdout,
yaml.UseLiteralStyleIfMultiline(true),
yaml.Indent(2), // Set indentation
//yaml.UseOrderedMap(), // Preserve map order
)
return enc.Encode(data)
}