-
Notifications
You must be signed in to change notification settings - Fork 16
/
pipe.go
56 lines (51 loc) · 1.05 KB
/
pipe.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
46
47
48
49
50
51
52
53
54
55
56
package someutils
import (
"fmt"
"io"
"os"
)
type Pipe struct {
In io.Reader
Out io.Writer
}
func (p *Pipe) Drain() {
go autoPipe(p.Out, p.In)
}
func (p *Pipe) CloseIfClosers() {
closer, ok := p.In.(io.Closer)
if ok {
pipereader, ok := p.In.(*io.PipeReader)
if ok {
err := pipereader.CloseWithError(io.EOF)
if err != nil {
fmt.Fprintln(os.Stderr, "Could not close inPipe (", err, ")")
}
} else {
err := closer.Close()
//never mind
if err != nil {
fmt.Fprintln(os.Stderr, "Could not close inPipe (", err, ")")
}
}
} else {
// fmt.Fprintln(os.Stderr, "inPipe not a Closer")
}
closer, ok = p.Out.(io.Closer)
if ok {
pipewriter, ok := p.Out.(*io.PipeWriter)
if ok {
err := pipewriter.CloseWithError(io.EOF)
if err != nil {
fmt.Fprintln(os.Stderr, "Could not close outPipe (", err, ")")
}
} else {
err := closer.Close()
//never mind
if err != nil {
fmt.Fprintln(os.Stderr, "Could not close outPipe (", err, ")")
}
}
} else {
// fmt.Fprintln(os.Stderr, "outPipe not a Closer")
}
}