Skip to content

Instantly share code, notes, and snippets.

@jochasinga
Created September 30, 2014 21:23
Show Gist options
  • Save jochasinga/d7ddfe4eaf0c00aea117 to your computer and use it in GitHub Desktop.
Save jochasinga/d7ddfe4eaf0c00aea117 to your computer and use it in GitHub Desktop.
Using defer to close file in Go
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