Like others have mentioned, RAII-style stuff doesn't work so well with a GC language.
Go does provide a "defer" statement, which cause a function call to execute when the current function returns. This makes it easy to visually co-locate resource acquisition and release, as well as ensuring the release code runs regardless of how the function is exited.
It looks like this:
f := os.Open("someFile")
defer f.Close() // will run when current function exits
Go does provide a "defer" statement, which cause a function call to execute when the current function returns. This makes it easy to visually co-locate resource acquisition and release, as well as ensuring the release code runs regardless of how the function is exited.
It looks like this:
It's easy and works well (IMO).