blob: e100140382d6200c7b12f0f9ade2eec77b71b394 [file] [log] [blame]
// +build ignore,OMIT
package main
import (
"bytes"
"fmt"
"io"
"os"
)
var (
_ = bytes.Buffer{}
_ = os.Stdout
)
// WriteCounter tracks the total number of bytes written.
type WriteCounter struct {
io.ReadWriter
count int
}
func (w *WriteCounter) Write(b []byte) (int, error) {
w.count += len(b)
return w.ReadWriter.Write(b)
}
// MAIN OMIT
func main() {
buf := &bytes.Buffer{}
w := &WriteCounter{ReadWriter: buf}
fmt.Fprintf(w, "Hello, gophers!\n")
fmt.Printf("Printed %v bytes", w.count)
}