Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
add MaybeClose (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeKolampas-Optable authored Feb 9, 2022
1 parent 200c093 commit 1f36397
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions io/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ func SafeCloser(closer io.Closer) io.Closer {
return &closeOnce{closer: closer}
}

// MaybeClose closes if the passed object implements io.Closer
// and does nothing otherwise
func MaybeClose(i interface{}) error {
if closer, ok := i.(io.Closer); ok {
return closer.Close()
}
return nil
}

// CloserFn implements the io.Closer interface for closures of the same
// signature.
type CloserFn func() error
Expand Down

0 comments on commit 1f36397

Please sign in to comment.