This code (at Go Playground at http://play.golang.org/p/BjWPVdQQrS):
package main
import "fmt"
type foodStruct struct {
fruit map[int]string
veggie map[int]string
}
func showFood(f map[int]map[int]string) {
fmt.Println(f[1][1])
}
func main() {
f := map[int]foodStruct{
1: {
fruit: map[int]string{1: "pear"},
veggie: map[int]string{1: "celery"},
},
}
fmt.Println(f[1].fruit[1])
g := map[int]map[int]string{1: map[int]string{1: "orange"}}
showFood(g)
// showFood(f.fruit) // Compile error: "f.fruit undefined (type map[int]foodStruct has no field or method fruit)"
}
prints:
pear
orange
Is there any way I can pass a form of variable f to showFood(), so that it prints "pear"? Passing f.fruit raises the compile error shown in the commented-out line above. The error is confusing to me, since foodStruct does have field fruit.