2020-06-07 10:52:00 +00:00
|
|
|
package iio
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2020-07-14 11:55:08 +00:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2020-06-07 10:52:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func CloseIfCloseable(r interface{}) error {
|
2020-07-14 11:55:08 +00:00
|
|
|
log.Debug("closing file...")
|
2020-06-07 10:52:00 +00:00
|
|
|
if r == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
closer, ok := r.(io.Closer)
|
|
|
|
if !ok {
|
2020-07-14 11:55:08 +00:00
|
|
|
log.Debug("file is not implementing close method")
|
2020-06-07 10:52:00 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return closer.Close()
|
|
|
|
}
|