|
|
@ -3,10 +3,8 @@ package mapping
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// To make .json & .yaml consistent, we just use json as the tag key.
|
|
|
|
// To make .json & .yaml consistent, we just use json as the tag key.
|
|
|
@ -43,12 +41,18 @@ func unmarshalYamlBytes(content []byte, v interface{}, unmarshaler *Unmarshaler)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func unmarshalYamlReader(reader io.Reader, v interface{}, unmarshaler *Unmarshaler) error {
|
|
|
|
func unmarshalYamlReader(reader io.Reader, v interface{}, unmarshaler *Unmarshaler) error {
|
|
|
|
content, err := ioutil.ReadAll(reader)
|
|
|
|
var res interface{}
|
|
|
|
if err != nil {
|
|
|
|
if err := yaml.NewDecoder(reader).Decode(&res); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return unmarshalYamlBytes(content, v, unmarshaler)
|
|
|
|
out := cleanupMapValue(res)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if m, ok := out.(map[string]interface{}); ok {
|
|
|
|
|
|
|
|
return unmarshaler.Unmarshal(m, v)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ErrUnsupportedType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// yamlUnmarshal YAML to map[string]interface{} instead of map[interface{}]interface{}.
|
|
|
|
// yamlUnmarshal YAML to map[string]interface{} instead of map[interface{}]interface{}.
|
|
|
|