type Table struct {
input map[string]map[string]
}
How to declare a multidimensional or recursive map?
input["var1"]["var2"] = "something"
type Table struct {
input map[map[string]]
}
returns error
syntax error: unexpected ]
You're looking for map[string]map[string]string
. The problem with your example is it's missing the type of the value in the inner map. Here's an example of how to init such a structure;
m := map[string]map[string]string{
"a": map[string]string{
"1":"A",
"2": "B",
},
"b": map[string]string{
"1": "C",
"2": "D",
},
}
Or following your example;
func main() {
m := map[string]map[string]string{}
m["var1"] = map[string]string{}
m["var1"]["var2"] = "something"
fmt.Println(m["var1"]["var2"])
}
That prints something.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With