This commit is contained in:
Prashanth Balasubramanian 2016-04-17 13:19:22 -07:00
parent d3a51031c3
commit 198a319fd6
1361 changed files with 239071 additions and 28102 deletions

View file

@ -2,6 +2,7 @@ package yaml
import (
"encoding"
"fmt"
"reflect"
"regexp"
"sort"
@ -74,8 +75,7 @@ func (e *encoder) marshal(tag string, in reflect.Value) {
return
}
in = reflect.ValueOf(v)
}
if m, ok := iface.(encoding.TextMarshaler); ok {
} else if m, ok := iface.(encoding.TextMarshaler); ok {
text, err := m.MarshalText()
if err != nil {
fail(err)
@ -165,6 +165,22 @@ func (e *encoder) structv(tag string, in reflect.Value) {
e.flow = info.Flow
e.marshal("", value)
}
if sinfo.InlineMap >= 0 {
m := in.Field(sinfo.InlineMap)
if m.Len() > 0 {
e.flow = false
keys := keyList(m.MapKeys())
sort.Sort(keys)
for _, k := range keys {
if _, found := sinfo.FieldsMap[k.String()]; found {
panic(fmt.Sprintf("Can't have key %q in inlined map; conflicts with struct field", k.String()))
}
e.marshal("", k)
e.flow = false
e.marshal("", m.MapIndex(k))
}
}
}
})
}