I remember reading about a feature of go in that you can declare a file handle to be closed when you first open it, and at the end of the (function? method? garbage collection?) it would automatically close.
What is the syntax for this and what is it called?
It sounds like you are after the defer
keyword. This lets you specify statements that will be executed when the function exits. For example:
defer f.Close()
Deferred cleanup routines are executed in the opposite order they are created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With