Files
server/ratelimit/reader.go
Lunny Xiao 0dc6782069
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
Support rate limit (#145)
Support rate limit

Reviewed-on: #145
Co-Authored-By: Lunny Xiao <xiaolunwen@gmail.com>
Co-Committed-By: Lunny Xiao <xiaolunwen@gmail.com>
2020-12-06 21:07:38 +08:00

28 lines
489 B
Go

// Copyright 2020 The goftp Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package ratelimit
import "io"
type reader struct {
r io.Reader
l *Limiter
}
// Read Read
func (r *reader) Read(buf []byte) (int, error) {
n, err := r.r.Read(buf)
r.l.Wait(n)
return n, err
}
// Reader returns a reader with limiter
func Reader(r io.Reader, l *Limiter) io.Reader {
return &reader{
r: r,
l: l,
}
}