I'm trying to write YAML for a datastructure which is both an int and a list of strings. But I'm having trouble getting the data structure and the YAML string to match. eg
package main
import (
"fmt"
"log"
yaml "gopkg.in/yaml.v2"
)
type ThingAndGroups struct {
Groups []string
Value int
}
var someStr = `
thing1:
Groups:
- g1
- g2
Value:
5
`
func main() {
t := make(map[string]ThingAndGroups)
err := yaml.Unmarshal([]byte(someStr), &t)
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Printf("--- t:
%v
", t)
}
Returns
map[thing1:{[] 0}]
How do I get thing1 to be a list of strings?