docs(limiter/traffic): add doc comments, unit tests

This commit is contained in:
ginuerzh
2026-05-24 20:54:34 +08:00
parent e9372ea44a
commit dc99f4731f
12 changed files with 1511 additions and 3 deletions
+3 -1
View File
@@ -9,7 +9,7 @@ import (
"github.com/go-gost/core/limiter/traffic"
)
// readWriter is an io.ReadWriter with traffic limiter supported.
// readWriter wraps an io.ReadWriter with traffic rate limiting applied to reads and writes.
type readWriter struct {
io.ReadWriter
rbuf bytes.Buffer
@@ -18,6 +18,8 @@ type readWriter struct {
key string
}
// WrapReadWriter wraps an io.ReadWriter with traffic rate limiting. If limiter
// is nil, the original ReadWriter is returned unchanged.
func WrapReadWriter(limiter traffic.TrafficLimiter, rw io.ReadWriter, key string, opts ...limiter.Option) io.ReadWriter {
if limiter == nil {
return rw