gotools/cmd/yamltool/parse.go

27 lines
424 B
Go
Raw Permalink 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
}
2025-01-10 18:38:43 +00:00
func parse(data []byte) (yaml.MapSlice, error) {
2025-01-07 08:27:12 +00:00
var result yaml.MapSlice
decoder := yaml.NewDecoder(bytes.NewReader(data),
yaml.UseOrderedMap())
err := decoder.Decode(&result)
if err != nil {
2025-01-10 18:38:43 +00:00
return nil, err
2025-01-07 08:27:12 +00:00
}
2025-01-10 18:38:43 +00:00
return result, nil
2025-01-07 08:27:12 +00:00
}