I am new to golang and you may find my question very silly. But still I have tried my leave best to find solution for my problem but no luck.
I need to keep mapping in below data structure which I want to use later in generating page from template. If I need to define below data structure in Python or Perl then I can do it easily do this.
Below is sample code for python.
{
'abc' : {
'1' : ['A', 'B', 'C']
}
'def' : {
'1': {
'key1':'val1',
'key2':'val2',
.....
...
},
'2':{
'key1':'val1',
'key2':'val2',
.....
...
},
....
....
}
}
Is there any easy way to achieve the same in golang? I understand that by uses of make(map[string]map[string]string) or
make(map[string]interface{}) . But still this seems me quite unreadable.
Update 1: Just clicked the idea that I can define the same structure in JSON format as well. But still is there any other way directly at language level?
It is probably easier to define a type (either at the package level or within the function), but you can define literal structs inline (arrays of these are usually seen in table-driven tests).
blah := struct{
s string
f int
}{"blah",12}
These can be nested arbitrarily, but it gets to be harder to read.