I can't have access to map inside Range loop method. I just want an equivalente method of normal map apply in sync.map https://play.golang.org/p/515_MFqSvCm
package main
import (
"sync"
)
type list struct {
code string
fruit
}
type fruit struct {
name string
quantity int
}
func main() {
lists := []list{list{"asd", fruit{"Apple", 5}}, list{"ajsnd", fruit{"Apple", 10}}, list{"ajsdbh", fruit{"Peach", 15}}}
map1 := make(map[string]fruit)
var map2 sync.Map
for _, e := range lists {
map1[e.code] = e.fruit
map2.Store(e.code, e.fruit)
}
//erase map
for k, _ := range map1 {
delete(map1, k)
}
//can´t pass map as argument,so I can´t delete it´s values
map2.Range(aux)
}
func aux(key interface{}, value interface{}) bool {
map2.Delete(key) //doesn´t work
return true
}