29 lines
552 B
Go
29 lines
552 B
Go
package sock
|
|
|
|
import "io"
|
|
|
|
type multiWriter struct {
|
|
writers []io.Writer
|
|
}
|
|
|
|
var _ io.Writer = &multiWriter{}
|
|
|
|
func (t *multiWriter) Write(p []byte) (n int, err error) {
|
|
for _, w := range t.writers {
|
|
w.Write(p)
|
|
}
|
|
return len(p), nil
|
|
}
|
|
|
|
func newMultiWriter(writers ...io.Writer) io.Writer {
|
|
allWriters := make([]io.Writer, 0, len(writers))
|
|
for _, w := range writers {
|
|
if mw, ok := w.(*multiWriter); ok {
|
|
allWriters = append(allWriters, mw.writers...)
|
|
} else {
|
|
allWriters = append(allWriters, w)
|
|
}
|
|
}
|
|
return &multiWriter{allWriters}
|
|
}
|