-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
nop.go
45 lines (36 loc) · 811 Bytes
/
nop.go
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 pio
import (
"io"
)
// IsNop can check wether an `w` io.Writer
// is a NopOutput.
func IsNop(w io.Writer) bool {
if isN, ok := w.(interface {
IsNop() bool
}); ok {
return isN.IsNop()
}
return false
}
type nopOutput struct{}
func (w *nopOutput) Write(b []byte) (n int, err error) {
// return the actual length in order to `AddPrinter(...)` to be work with io.MultiWriter
return len(b), nil
}
// IsNop defines this wrriter as a nop writer.
func (w *nopOutput) IsNop() bool {
return true
}
// NopOutput returns an `io.Writer` which writes nothing.
func NopOutput() io.Writer {
return &nopOutput{}
}
type nopCloser struct{}
func (c *nopCloser) Close() error {
return nil
}
// NopCloser returns an `io.Closer` which
// does nothing.
func NopCloser() io.Closer {
return &nopCloser{}
}