2016. szeptember 13., kedd 3:50:45 UTC+2 időpontban davidmi...@gmail.com a következőt írta: > > My response is inline..... > > On Monday, September 12, 2016 at 7:43:12 PM UTC-4, Keith Randall wrote: >> >> Tamás's suggestion of using [4]string as the key is a good one. You >> could use any struct you want as well, if you want to name the parts of the >> key. >> > > I tried that. I can't seem to get it to work. I'm clearly doing something > wrong, probably because I am misunderstanding Tamás's response. > > Test_Map := make(map[[4]string]string) > > I've tried this way..... > > > Test_Map["Folder_1"]["Folder_2"]["Folder_3"]["Folder_4"] = "File_Name_1" > > > As others already said, for TestMap := make(map[[4]string]string) TestMap[{"Folder_1","Folder_2","Folder_3","Folder_4"}] = "File_Name_1" will work.
If you really want a multidimensional array, you can use a map[string]interface{}, but then you must check (or know) whether the actual value at that key is a string or another map[string]interface{}: TestMap := map[string]interface{}{"Folder_1": map[string]interface{}{"Folder_2": map[string]interface{}{"Folder_3": map[string]interface{}{"Folder_4": "File_Name_1"}}}} fn := ((((TestMap["Folder_1"].(map[string]interface{}))["Folder_2"].(map[string]interface{}))["Folder_3"].(map[string]interface{})).(map[string]interface{}))["Folder_4"].(string) If you really want to use it such, you should create a type for map[string]interface{}, and add accessor methods to ease up usage. >From the usage description, I feel you want to use multidimensional arrays everywhere. That's not the best approach. With Go you have slices, too! And of course you can build other data structures right for the actual problem! -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.