-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_writer.go
More file actions
45 lines (39 loc) · 796 Bytes
/
multi_writer.go
File metadata and controls
45 lines (39 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package peanut
var _ Writer = &multiWriter{}
// multiWriter implements peanut.Writer
type multiWriter struct {
writers []Writer
}
// MultiWriter creates a writer that duplicates its method calls to all the provided writers.
func MultiWriter(writers ...Writer) Writer {
return &multiWriter{writers: writers}
}
func (mw *multiWriter) Write(x interface{}) error {
for _, w := range mw.writers {
err := w.Write(x)
if err != nil {
return err
}
}
return nil
}
func (mw *multiWriter) Close() error {
var xerr error
for _, w := range mw.writers {
err := w.Close()
if err != nil {
xerr = err
}
}
return xerr
}
func (mw *multiWriter) Cancel() error {
var xerr error
for _, w := range mw.writers {
err := w.Cancel()
if err != nil {
xerr = err
}
}
return xerr
}