Is there a better way to highlight the contents of this array, for example, by automatically calling the NewThing() constructor instead of manually creating each element?
package main import "sync" type Thing struct { lock *sync.RWMutex data chan int } func NewThing() *Thing { return &Thing{ lock: new(sync.RWMutex), data: make(chan int) } } func main() { n := 10 things := make([]*Thing, n) for i := 10; i < n; i++ { things[i] = NewThing() } }
I understand that I allocate an array of pointers, my other attempts were unsuccessful, and the data was not an initialized channel. This is just a contrived example.
Thanks!
source share