Adding call to check(err) after os.Open

Clearly we were just able to read the content via ioutil.ReadFile but for consistency I think it would be better to call check(err) after the call to os.Open("/tmp/dat") on line 34.

Tools like errcheck (https://github.com/kisielk/errcheck) will complain about uncaught / unhandled err's. Also can we really be sure some 3rd party process didn't nuke '/tmp' during execution :-)
This commit is contained in:
Yousef Ourabi 2014-05-11 17:14:20 -07:00
parent 65473fc225
commit f6f60540af

View File

@ -32,6 +32,7 @@ func main() {
// parts of a file are read. For these tasks, start // parts of a file are read. For these tasks, start
// by `Open`ing a file to obtain an `os.File` value. // by `Open`ing a file to obtain an `os.File` value.
f, err := os.Open("/tmp/dat") f, err := os.Open("/tmp/dat")
check(err)
// Read some bytes from the beginning of the file. // Read some bytes from the beginning of the file.
// Allow up to 5 to be read but also note how many // Allow up to 5 to be read but also note how many