@kinsey If os.Open (or os.Create) returns an error then the file pointer returned will be nil. So defer file.Close() would be... not ok.. wait? No, you can call Close() on a nil *os.File!
TIL
@quirk actually, i checked the source code, and you can call Close() on a nil *os.File, but it gives an error. and if there's an error opening the file you won't have an opened file to close anyway, so i thought of a better Standard Thing To Do maybe
inputFile, err := os.Open("/path/to/file")
if err == nil {
defer inputFile.Close()
} else {
// handle error...
}
@kinsey I'll return an error, yea, but you can just ignore the return value in that case.