-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
51 lines (42 loc) · 843 Bytes
/
util.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
package main
import (
"fmt"
"io"
"os"
eventlog "github.com/ipfs/go-ipfs/thirdparty/eventlog"
)
var log = eventlog.Logger("seccat")
func exit(format string, vals ...interface{}) {
if format != "" {
fmt.Fprintf(os.Stderr, "seccat: error: "+format+"\n", vals...)
}
Usage()
os.Exit(1)
}
func out(format string, vals ...interface{}) {
if verbose {
fmt.Fprintf(os.Stderr, "seccat: "+format+"\n", vals...)
}
}
type logRW struct {
n string
rw io.ReadWriter
}
func (r *logRW) Read(buf []byte) (int, error) {
n, err := r.rw.Read(buf)
if err == nil {
log.Debugf("%s read: %v", r.n, buf)
}
return n, err
}
func (r *logRW) Write(buf []byte) (int, error) {
log.Debugf("%s write: %v", r.n, buf)
return r.rw.Write(buf)
}
func (r *logRW) Close() error {
c, ok := r.rw.(io.Closer)
if ok {
return c.Close()
}
return nil
}