add flag to flatten a single-value array
Created by: alaska
I'm currently using this library to create plists for launchd. In a couple of locations, the specification says <dictionary [of something] or array of dictionaries [of the same thing]>
. I can't imagine launchd is the only place to do this. It would be nice to be able to have a flag flattensingle
such that, given
type Foo map[string]string
type Dict struct {
Bar []Foo `plist:",omitempty,flattensingle"`
}
func main() {
d := Dict{
Bar: []Foo{
Foo{
"name": "one",
"num": "two",
},
},
}
o, e := plist.MarshalIndent(d, plist.XMLFormat, " ")
fmt.Println(e)
fmt.Println(string(o))
}
The output would be
<plist version="1.0">
<dict>
<key>Bar</key>
<dict>
<key>name</key>
<string>one</string>
<key>num</key>
<string>two</string>
</dict>
</dict>
</plist>
Rather than what it is now:
<plist version="1.0">
<dict>
<key>Bar</key>
<array>
<dict>
<key>name</key>
<string>one</string>
<key>num</key>
<string>two</string>
</dict>
</array>
</dict>
</plist>