32 lines
512 B
Go
32 lines
512 B
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
package ext
|
|
|
|
import (
|
|
"io"
|
|
)
|
|
|
|
type Closer func() error
|
|
|
|
func WriteAddCloser(w io.WriteCloser, c Closer) io.WriteCloser {
|
|
a := writeAddCloser{ WriteCloser: w, AddClose: func() (err error) {
|
|
if err = w.Close(); err != nil {
|
|
return
|
|
}
|
|
if c != nil {
|
|
return c()
|
|
}
|
|
return
|
|
} }
|
|
return a
|
|
}
|
|
|
|
type writeAddCloser struct {
|
|
io.WriteCloser
|
|
AddClose Closer
|
|
}
|
|
|
|
func (w writeAddCloser) Close() error {
|
|
return w.AddClose()
|
|
}
|