Created
September 30, 2014 21:23
-
-
Save jochasinga/d7ddfe4eaf0c00aea117 to your computer and use it in GitHub Desktop.
Using defer to close file in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "os" | |
func main() { | |
file, err := os.Open("test.txt") | |
defer file.Close() | |
if err != nil { | |
// handle the error here | |
return "", err | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment