gotools/cmd/yamltool/parse.go

27 lines
405 B
Go
Raw Normal View History

2025-01-07 08:27:12 +00:00
package main
import (
"bytes"
"github.com/goccy/go-yaml"
"os"
)
func read(file string) []byte {
data, err := os.ReadFile(file)
if err != nil {
panic(err)
}
return data
}
func parse(data []byte) yaml.MapSlice {
var result yaml.MapSlice
decoder := yaml.NewDecoder(bytes.NewReader(data),
yaml.UseOrderedMap())
err := decoder.Decode(&result)
if err != nil {
panic(err)
}
return result
}