I am learning to use the map of maps. In the following example, there are three nested maps.
package main
import (
"fmt"
)
func main() {
var data = map[string]map[string]map[string]string{}
data["Date_1"] = map[string]map[string]string{}
data["Date_1"] = make(map[string]map[string]string, 1)
data["Date_1"] = make(map[string]map[string]string, 0)
data["Date_1"]["Sistem_A"] = map[string]string{}
data["Date_1"]["Sistem_A"] = make(map[string]string, 0)
data["Date_1"]["Sistem_A"] = make(map[string]string, 0)
data["Date_1"]["Sistem_A"]["command_1"] = "white"
data["Date_1"]["Sistem_A"]["command_2"] = "blue"
data["Date_1"]["Sistem_A"]["command_3"] = "red"
fmt.Println("data: ", data)
}
Output
data: map[Date_1:map[Sistem_A:map[command_1:white command_2:blue command_3:red]]]
The problem is that if I want to add the values in one step I get a panic: assignment to entry in nil map.
package main
import (
"fmt"
)
func main() {
var data = map[string]map[string]map[string]string{}
data["Date_1"] = map[string]map[string]string{}
data["Date_1"] = make(map[string]map[string]string, 0)
data["Date_1"] = make(map[string]map[string]string, 0)
data["Date_1"]["Sistem_A"] = map[string]string{}
data["Date_1"]["Sistem_A"] = make(map[string]string, 0)
data["Date_1"]["Sistem_A"] = make(map[string]string, 0)
data["Date_1"]["Sistem_A"]["command_1"] = "white"
data["Date_1"]["Sistem_A"]["command_2"] = "blue"
data["Date_1"]["Sistem_A"]["command_3"] = "red"
data["Date_2"]["Sistem_A"]["command_5"] = "violet"
fmt.Println("data: ", data)
}
Output
panic: assignment to entry in nil map
There is very little guidance information at this point. Could you help me?
Thank you.