Documentation
¶
Overview ¶
Package diagio implements I/O wrappers which can be useful for debugging and other diagnostics purposes.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Count ¶
Count takes anything and calls Count() on it and returns the result.
Returns -1 if Count() method does not exist.
This is useful for passing around an ordinary io.Reader or an ordinary io.Writer and later calling Count() on it.
Example ¶
package main
import (
"fmt"
"io"
"os"
"github.com/snabb/diagio"
)
func main() {
cw := diagio.NewCounterWriter(os.Stdout)
f := func(w io.Writer) {
fmt.Fprintln(w, "foobar")
fmt.Println(diagio.Count(w))
}
f(cw)
}
Output: foobar 7
Types ¶
type CounterReader ¶
type CounterReader struct {
// contains filtered or unexported fields
}
CounterReader implements io.Reader. Number of bytes read is tracked.
Example ¶
package main
import (
"bytes"
"fmt"
"io"
"github.com/snabb/diagio"
)
func main() {
input1 := bytes.NewBufferString("hello world")
input2 := diagio.NewCounterReader(input1)
io.Copy(io.Discard, input2)
fmt.Println(input2.Count())
}
Output: 11
func NewCounterReader ¶
func NewCounterReader(r io.Reader) (cr *CounterReader)
NewCounterReader wraps io.Reader and returns CounterReader.
func (*CounterReader) Count ¶
func (cr *CounterReader) Count() (n int64)
Count returns the number of bytes read from the CounterReader.
type CounterWriter ¶
type CounterWriter struct {
// contains filtered or unexported fields
}
CounterWriter implements io.Writer. Number of bytes written is tracked.
Example ¶
package main
import (
"fmt"
"os"
"github.com/snabb/diagio"
)
func main() {
cw := diagio.NewCounterWriter(os.Stdout)
fmt.Fprintln(cw, "hello world")
fmt.Println(cw.Count())
}
Output: hello world 12
func NewCounterWriter ¶
func NewCounterWriter(w io.Writer) (cw *CounterWriter)
NewCounterWriter wraps io.Writer and returns CounterWriter.
func (*CounterWriter) Count ¶
func (cw *CounterWriter) Count() (n int64)
Count returns the number of bytes written to the CounterWriter.
type DiagReader ¶
type DiagReader struct {
// contains filtered or unexported fields
}
DiagReader implements io.Reader. Diagnostics output is produced whenever it is read from.
Example ¶
package main
import (
"bytes"
"io"
"os"
"github.com/snabb/diagio"
)
func main() {
input1 := bytes.NewBufferString("hello world")
input2 := diagio.NewDiagReader(input1, os.Stdout)
io.Copy(io.Discard, input2)
}
Output: >>> Read 8192 bytes at 0 (start) === 00000000 68 65 6c 6c 6f 20 77 6f 72 6c 64 |hello world| <<< Read 11 bytes (err = <nil>) (end) === >>> Read 8192 bytes at 11 (start) === <<< Read 0 bytes (err = EOF) (end) ===
func NewDiagReader ¶
func NewDiagReader(r io.Reader, diagOutput io.Writer) (dr *DiagReader)
NewDiagReader wraps io.Reader and returns DiagReader.
func (*DiagReader) PrintHex ¶
func (dr *DiagReader) PrintHex(v bool)
PrintHex enables or disables hex dump output. The default is enabled.
func (*DiagReader) PrintInfo ¶
func (dr *DiagReader) PrintInfo(v bool)
PrintInfo enables or disables output of number of bytes read, stream position and possible error code. The default is enabled.
type DiagWriter ¶
type DiagWriter struct {
// contains filtered or unexported fields
}
DiagWriter implements io.Writer. Diagnostics output is produced whenever it is written to.
Example ¶
package main
import (
"fmt"
"io"
"os"
"github.com/snabb/diagio"
)
func main() {
output := diagio.NewDiagWriter(io.Discard, os.Stdout)
fmt.Fprint(output, "hello world")
}
Output: >>> Write 11 bytes at 0 (start) === 00000000 68 65 6c 6c 6f 20 77 6f 72 6c 64 |hello world| <<< Wrote 11 bytes (err = <nil>) (end) ===
func NewDiagWriter ¶
func NewDiagWriter(w io.Writer, diagOutput io.Writer) (dw *DiagWriter)
NewDiagWriter wraps io.Writer and returns DiagWriter.
func (*DiagWriter) PrintHex ¶
func (dw *DiagWriter) PrintHex(v bool)
PrintHex enables or disables hex dump output. The default is enabled.
func (*DiagWriter) PrintInfo ¶
func (dw *DiagWriter) PrintInfo(v bool)
PrintInfo enables or disables output of number of bytes written, stream position and possible error code. The default is enabled.