Do you mind explaining why defer is a problem in Go? I only have experience with Java’s try-with-resources which I like a lot, it looks like C# using is similar.
1. You cannot remotely easily wire them in a SIGINT scenario. I have done it, it was a load of plumbing and I wrote an equivalent to Java’s shutdown hook and tied it to sigterm and sigint then called that same hook in the normal shutdown path to simulate the defer call cycle.
2. “using” or “with” in other languages is nice and explicit about when it runs and you can easily run it before your function exits. In the case of go you need to wrap some function to force this same behavior in Go and it looks very forced.
Defer is fine, especially if you’re writing something with a simple life cycle.
I just end up using it less when I need to support cleanup functions being called no matter what in a graceful shutdown.