I want to populate an array of arrays inside a subroutine. I am trying to do this using a channel. I am learning go, so unclear if this is the right way, so please correct me if I am going in the wrong direction, but my code never returns. What am I doing wrong?
var c = make(chan [3][4]string)
var mymap = map[int]string{
0: "www.foo.com",
1: "www.bar.com",
2: "www.baz.com",
3: "www.faz.com",
}
values := [3][4]string{{"A", "B", "C", "D"}}
var wg sync.WaitGroup
wg.Add(4) // one thread per index, total 4 indexes
for idx, url := range mymap {
go func(idx int, url string) {
defer wg.Done()
values[1][idx] = "someone"
values[2][idx] = "something"
c <- values
}(name, url)
}
wg.Wait()
close(c)