I want to create result object json with dynamic structure of data, ex in func1 the result is like this
{
'result': 'this is result',
'content': {
'func1' : 'value',
'some_desc_func1': 'value'
}
}
and func2 maybe the result is just (focus on content) like this
{
'result': 'this is result',
'content': {
'func2' : 'value'
}
}
As this reference https://stackoverflow.com/a/35657622/4476788, i want to show result json with just one key of result.
Like this
{
'result': 'this is result',
'content': {
'key' : 'value'
}
}
And not like this
[
{
'result_1' : 'answer 1'
},
{
'result_2' : 'answer 2'
}
]
i try to update the play ground of the answer but it showing error
type Brand struct {
Name string
}
var database map[string]interface{}
func init() {
database = make(map[string]interface{})
brands := make([]Brand, 1)
brands = Brand{"Gucci"}
database["brands"] = brands
}
You can try run in here https://play.golang.org/p/mKCwKEVI7E
it showing error
tmp/sandbox651609402/main.go:22: cannot use Brand literal (type Brand) as type []Brand in assignment