Use "defer close(ch)". If there is a break or a panic, the channel will be closed.
https://groups.google.com/forum/#!topic/golang-nuts/RmfHSHE9...
Note that there is no requirement that you close channels-- they aren't like file descriptors. They will be garbage collected after they're no longer needed.
goroutines, on the other hand, will stick around unless you clean them up. goroutines aren't iterators, and you shouldn't use them as iterators. They're more analogous to threads.