Hi All,
I have a use case where i am creating a new map of the following type. I basically want to check if the key-value is present in the map, if so then i want to append the array of the map and insert the value. If not, then i want to initialize the array and append it.
The issue i am facing is that the map i am creating is empty- how do i add values to it, so my condition always fails. How do i fix this?
FYI: i pass a request like below to this function, which i am checking for the value in (for the map):
Request:
[{
“Category”: “TP”,
“Name”: “Golang”,
}]
type Example struct {
Category string `json:"category"`
Name string `json:"name"`
}
for i := range Example{
dict := make(map[string][]Example)
if count, ok := dict["Category"]; ok {
fmt.Printf("Found %d\n", count)
} else {
fmt.Println("not found")
fmt.Println(i)
}
}