You wouldn't do that in java either. The right thing to do in java is to have a finally block that closes it somewhere near where you opened.
To perform a cleanup, you must use a similar pattern to jump using the defer function. For example, if you did this (java):
try { open(); // do stuff } finally { close(); }
In go, you would do this:
open(); defer close(); // do stuff
Dustin
source share