Files
server/ratelimit/writer.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

27 lines
482 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 writer struct {
w io.Writer
l *Limiter
}
// Write Write
func (w *writer) Write(buf []byte) (int, error) {
w.l.Wait(len(buf))
return w.w.Write(buf)
}
// Writer returns a writer with limiter
func Writer(w io.Writer, l *Limiter) io.Writer {
return &writer{
w: w,
l: l,
}
}