I have a map[string]interface{} called mapped:
mapped map[stringinterface{}
I want to iterate through it checking to see if either of these keys exist:
- columns
- rows
Then if so, I want to append the row or column to a slice of strings called:
- columnOrRowArray
I understand that if I just needed to find, for example columns, within mapped I can do this:
var columnOrRowArray []string
if columnsOrRows, ok := mapped["columns"].([]interface{}); ok {
for _, columnOrRow := range columnsOrRows {
if columnOrRowValueIsString, ok = columnOrRow.(string); ok {
columnOrRowArray = append(columnOrRowArray, columnOrRowValueIsString)
}
}
}
What would be a clean way without me duplicating the above for using row logic for the mapped["rows"]?
I want to do something that is basically this:
columnsOrRows, ok := mapped["columns"].([]interface{}) || mapped["rows"].([]interface{}); ok {
So in plain English, "if mapped has a the column or row key, assign to variable columnsOrRows"
Obviously I know the syntax for that is wrong, but I can't find an example of someone doing this