From 307476764a60bd578f1aed4840e522d52eb129c8 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Sun, 4 Dec 2022 21:16:39 +0100 Subject: [PATCH] Add internal/util/yaml.go --- internal/util/yaml.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 internal/util/yaml.go diff --git a/internal/util/yaml.go b/internal/util/yaml.go new file mode 100644 index 0000000..21cd88b --- /dev/null +++ b/internal/util/yaml.go @@ -0,0 +1,14 @@ +package util + +import ( + "bytes" + + "gopkg.in/yaml.v3" +) + +// YamlUnmarshalStrict unmarshals YAML data with an error when unknown fields are present. +func YamlUnmarshalStrict(in []byte, out interface{}) error { + dec := yaml.NewDecoder(bytes.NewReader(in)) + dec.KnownFields(true) + return dec.Decode(out) +}