I have a map of arrays of maps map[string][]map[string]string
, only, when I get the data, it's in the format map[interface{}]map[interface{}][]map[interface{}]interface{}
, so I'm left to do a bunch of nested type assertions, which is really clunky, takes a long time to write, is hard to read/write, and is probably error prone, like this;
if key == "identities" {
idErrMessage := "Sorry, there was a problem with an identity"
idArray, ok := setting.(map[string]interface{})
if ok {
for idType, ids := range idArray {
idGroupArray, ok := ids.([]interface{})
if ok {
for _, idGroup := range idGroupArray {
id, ok := idGroup.(map[interface{}]interface{})
if ok {
log.Println("type:", idType)
for key, val := range id {
log.Printf("%v: %v", key, val)
}
} else {
log.Fatal(idErrMessage)
}
}
} else {
log.Fatal(idErrMessage)
}
}
} else {
log.Fatal(idErrMessage)
}
}
I've been searching for a few hours now, and I can't seem to find an easier way to do this than the code above.
Is there anyway I can just v, ok := setting.(map[string]map[string][]map[string]string)
, or am I just stuck with the code above?