Skip to content
Golang counters for readers/writers
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Initial commit Oct 14, 2015
.travis.yml add travis conf Jun 14, 2016
LICENSE update LICENSE Oct 14, 2015
README.md add badges Jun 14, 2016
reader.go fix golint Dec 21, 2015
reader_test.go fix govet Dec 21, 2015
response_writer.go Update response_writer.go Nov 4, 2017
response_writer_test.go fix govet Dec 21, 2015
writer.go fix golint Dec 21, 2015
writer_test.go fix govet Dec 21, 2015

README.md

datacounter

Golang counters for readers/writers

Build Status GoDoc Go Report Card

Examples

ReaderCounter

buf := bytes.Buffer{}
buf.Write(data)
counter := datacounter.NewReaderCounter(&buf)
io.Copy(ioutil.Discard, counter)
if counter.Count() != dataLen {
	t.Fatalf("count mismatch len of test data: %d != %d", counter.Count(), len(data))
}`

WriterCounter

buf := bytes.Buffer{}
counter := datacounter.NewWriterCounter(&buf)
counter.Write(data)
if counter.Count() != dataLen {
	t.Fatalf("count mismatch len of test data: %d != %d", counter.Count(), len(data))
}

http.ResponseWriter Counter

handler := func(w http.ResponseWriter, r *http.Request) {
	w.Write(data)
}
req, err := http.NewRequest("GET", "http://example.com/foo", nil)
if err != nil {
	t.Fatal(err)
}
w := httptest.NewRecorder()
counter := datacounter.NewResponseWriterCounter(w)
handler(counter, req)
if counter.Count() != dataLen {
	t.Fatalf("count mismatch len of test data: %d != %d", counter.Count(), len(data))
}
You can’t perform that action at this time.