Simple counter-like type with fancy .String()
formatter.
One may find useful .Rate(secs)
or .BitRate(secs)
formatters too.
The code like
…
import (
"time"
"fmt"
. "github.com/jn0/go-types" // here we go
)
…
var traffic Bytes
var t0 time.Time
var dt time.Duration
…
for t0 = time.Now();; {
data := endpoint.Read()
traffic.Add(uint64(len(data)))
…
}
dt = time.Now().Sub(t0)
fmt.Printf("Got %s in %s at %s.\n",
traffic, dt, traffic.BitRate(dt.Seconds()))
…
will show up something like
Got 123.456MiB in 12.123456s at 81.465Mi bps.
100% test covered