from info_snap_yaml.go:
type slotYaml struct {
Interface string `yaml:"interface"`
Attrs map[string]interface{} `yaml:"attrs,omitempty"`
Apps []string `yaml:"apps,omitempty"`
Label string `yaml:"label"`
}
Example yaml:
slots:
foo:
interface: bar
baz:
- norf
- qux
quux:
- corge
This is fine (gets 'baz' and 'quux'):
for attr := range slot.Attrs {
...
}
Can see the data with:
fmt.Printf("%#+v\n", slot.Attrs)
fmt.Printf("%#+v\n", slot.Attrs["baz"])
eg:
map[string]interface {}{"baz":[]interface {}{"norf", "qux"}}
[]interface {}{"norf", "qux"}
None of these work to get at 'norf' and 'qux':
fmt.Printf("%d\n", len(slot.Attrs["baz"]))
invalid argument slot.SlotInfo.Attrs["baz"] (type interface {}) for len
fmt.Printf("%d\n", len(slot.Attrs["baz"].(string)))
... Panic: interface conversion: interface is []interface {}, not string (PC=0x45A35E)
for p := range slot.Attrs["baz"] {
fmt.Printf("%s\n", p.(string))
}
cannot range over slot.SlotInfo.Attrs["baz"] (type interface {})
for i, p := range slot.Attrs["baz"] {
fmt.Printf("%s\n", p.(string))
}
cannot range over slot.SlotInfo.Attrs["baz"] (type interface {})
for p := range slot.Attrs["baz"].([]string) {
fmt.Printf("%s\n", p)
}
... Panic: interface conversion: interface is []interface {}, not []string (PC=0x45A35E)
for p := range slot.Attrs["baz"].(string) {
fmt.Printf("%s\n", p)
}
... Panic: interface conversion: interface is []interface {}, not string (PC=0x45A35E)
AIUI I cannot assert '.([]string)' with interfaces for '[]interface{}' and
instead must assert each individual 'interface{}', but I have no way to iterate
over '[]interface{}'. Note: I can go from '[]string' to '[]interface{}' just
fine, but can't go from '[]interface{}' to '[]string'.
What am I missing?