3 ms·
if _, err := os.Open("file.go"); err != nil { //handle error } // Do stuff with file but you need to split that into 2 lines, just like the go
by signa11 13y ago
if _, err := os.Open("file.go"); err != nil {
//handle error
}
// Do stuff with file
but you need to split that into 2 lines, just like the good article says i.e.
file, err := os.Open("abcd")
if err != nil {
// <handle os.Open(...) errors
}
otherwise, outside the 'if {...}' block, 'file' is undefined.