gotools/cmd/yamltool/parse.go
2025-01-10 19:38:43 +01:00

27 lines
424 B
Go

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, error) {
var result yaml.MapSlice
decoder := yaml.NewDecoder(bytes.NewReader(data),
yaml.UseOrderedMap())
err := decoder.Decode(&result)
if err != nil {
return nil, err
}
return result, nil
}