1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-08 06:55:28 +02:00

Improve nil check in utility.Close

This commit is contained in:
Elliott Stoneham 2016-05-16 10:23:06 +01:00
parent 7925695d0b
commit 0a40c96849

View file

@ -4,8 +4,12 @@ import "io"
import "github.com/documize/community/wordsmith/log"
// Close is a convenience function to close an io.Closer, usually in a defer.
func Close(f io.Closer) {
if f != nil && f != io.Closer(nil) {
log.IfErr(f.Close())
func Close(f interface{}) {
if f != nil {
if ff, ok := f.(io.Closer); ok {
if ff != io.Closer(nil) {
log.IfErr(ff.Close())
}
}
}
}