Documentation
¶
Overview ¶
Package rate limits the bytes a client's connections transfer, on top of github.com/djylb/byterate.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRateConn ¶
func NewRateConn(conn io.ReadWriteCloser, r *Rate) io.ReadWriteCloser
NewRateConn limits conn's reads and writes together by r. A net.Conn stays a net.Conn. With a nil r, conn is returned as it is. Close wakes a Read or Write waiting for the limit.
Types ¶
type Rate ¶
type Rate struct {
// contains filtered or unexported fields
}
Rate is a byte rate limiter shared by all connections of a client: their reads and writes are charged to the same bucket. A limit <= 0 means unlimited. The zero value is an unlimited, running Rate.
Its JSON form is {"NowRate":...,"Limit":...}, the measured throughput and the limit in bytes per second. Decoding ignores both: they are runtime state, and the limit comes from the client's configuration.
func (*Rate) Limit ¶ added in v0.33.13
Limit returns the limit in bytes per second, or 0 if unlimited.
func (*Rate) MarshalJSON ¶ added in v0.33.13
func (*Rate) ResetLimit ¶ added in v0.33.14
ResetLimit sets the limit, wakes waiting connections and starts over with a full burst.