// Copyright 2024 Matthew Rich . 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() }