blob: 379ca0b96c8276766c756a4b51a1f52b7e9cadb7 [file] [log] [blame]
// +build 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)
}