Error handling…making it elegant with Go 2.
One of the first striking observations of a beginner in Go is the error handling. With Go, the if checks can be a little daunting and not a very elegant option coming from Java. The try catch-es appear to still be a valid construct.
Here’s an example,
nbytes, err := io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
if (err != nil ) {
ch <- fmt.Sprintf(“while reading %s: %v “, url, err)
return