8 "golang.org/x/net/context"
9 "golang.org/x/time/rate"
12 type rateLimitedReader struct {
17 func (me rateLimitedReader) Read(b []byte) (n int, err error) {
18 // Wait until we can read at all.
19 if err := me.l.WaitN(context.Background(), 1); err != nil {
22 // Limit the read to within the burst.
23 if me.l.Limit() != rate.Inf && len(b) > me.l.Burst() {
28 if !me.l.ReserveN(time.Now(), n-1).OK() {
29 panic(fmt.Sprintf("burst exceeded?: %d", n-1))