I am new to golang.
I am trying to create an object which looks like this:
ACK: "Success"
BUILD: "15420584"
CORRELATIONID: "1eac210c7c07a"
TIMESTAMP: "2015-03-17T11:08:47Z"
VERSION: "69.0"
ITEMS:
0:
AMT: "60.00"
CURRENCYCODE: "USD"
FEEAMT: "0.00"
NAME: "Test Store"
NETAMT: "60.00"
STATUS: "Completed"
TIMESTAMP: "2014-03-11T07:52:05Z"
TIMEZONE: "GMT"
TRANSACTIONID: "9F4923492C3800000"
TYPE: "Payment"
1: ....
Here's the code for that. But it gives an error invalid operation: finalResult["ITEMS"]["0"] (type interface {} does not support indexing)
I don't want to use struct for finalResult since the total key and their names can vary
finalResult := make(map[string]interface{})
type itemVaues map[string]string
finalResult["ITEMS"] = make(map[string]itemVaues)
if _, ok := finalResult["ITEMS"]["0"]; !ok {
tempMap := make(itemVaues)
tempMap["ACK"] = "Success"
tempMap["CURRENCYCODE"] = "USD"
finalResult["ITEMS"]["0"] = tempMap
fmt.Println("finalResult",finalResult)
}
Please help.