On Thursday, March 21, 2019 at 10:41:05 AM UTC+1, Amnon Baron Cohen wrote:
>
> The idiomatic Go way is to write
>
> defer ifDB.Close()
>
> Simple is better than clever.
>
> + Readability does matter.
>
>
Do you think logging the possible error from Close is clever?
If you want readability you can define a CloseWithLog function somewhere:
func CloseWithLog(c io.Closer, prefix string) {
if err := c.Close(); err != nil {
log.Println(prefix + " " + err.Error())
}
}
defer CloseWithLog(ifDB)
https://play.golang.org/p/aGQi30-n_hS
This is stil readable *but* any problem with Close will be logged to a log
file.
> [...]
Manlio Perillo
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.