'How to upsert into concurrent map while iterating over regular map?

I need to have a map of string as key and unique (no dupes) int64 array as value so I decided to use something like below so that value can act as a set.

var customerCatalog = make(map[string]map[int64]bool)

Above map is populated with some data in it. Now I am trying to populate my concurrent map in golang by reading above regular customerCatalog map but I am getting error:

for k, v := range customerCatalog {
  r.customerCatalog.Upsert(k, v, func(exists bool, valueInMap interface{}, newValue interface{}) interface{} {
    typedNewValue := newValue.([]int64)
    if !exists {
      return typedNewValue
    }
    typedValueInMap := valueInMap.([]int64)
    return append(typedValueInMap, typedNewValue...)
  })
}

This is the error I am getting. I am using upsert method as shown here

panic: interface conversion: interface {} is map[int64]bool, not []int64

What is wrong I am doing?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source