Skip to content

Instantly share code, notes, and snippets.

@ik5
Created May 28, 2014 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ik5/a2ce33e11a03183e1206 to your computer and use it in GitHub Desktop.
Save ik5/a2ce33e11a03183e1206 to your computer and use it in GitHub Desktop.
defer in go
func open_file {
f, err := os.Open("/tmp/a_file")
if err != nil {
log.Fatal("Unable to open a_file")
}
defer f.Close()
// do something here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment