2017-07-09 22:17:20 +02:00
|
|
|
package utils
|
2017-06-21 15:42:49 +02:00
|
|
|
|
|
|
|
import yaml "gopkg.in/yaml.v2"
|
|
|
|
|
2017-08-20 23:45:25 +02:00
|
|
|
// UnmarshalYAMLInterface is a wrapper for yaml.Unmarshal that
|
2017-06-21 15:42:49 +02:00
|
|
|
// knows how to unmarshal maps and lists.
|
|
|
|
func UnmarshalYAMLInterface(b []byte, i *interface{}) error {
|
2017-08-20 23:45:25 +02:00
|
|
|
var m yaml.MapSlice
|
2017-06-21 15:42:49 +02:00
|
|
|
err := yaml.Unmarshal(b, &m)
|
|
|
|
switch err.(type) {
|
|
|
|
case *yaml.TypeError:
|
|
|
|
// Work around https://github.com/go-yaml/yaml/issues/20
|
|
|
|
var s []interface{}
|
|
|
|
err = yaml.Unmarshal(b, &s)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
*i = s
|
|
|
|
default:
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
*i = m
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|