wrapper

package
v0.28.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package wrapper provides net.Conn, net.PacketConn, and io.ReadWriter wrappers that apply traffic rate limiting to reads and writes.

Index

Constants

This section is empty.

Variables

View Source
var ErrRateLimited = errRateLimited

ErrRateLimited is returned when a write exceeds the rate limit.

Functions

func WrapConn

func WrapConn(c net.Conn, tlimiter traffic.TrafficLimiter, key string, opts ...limiter.Option) net.Conn

WrapConn wraps a net.Conn with traffic rate limiting. If tlimiter is nil, the original conn is returned unchanged.

func WrapListener

func WrapListener(service string, ln net.Listener, limiter traffic.TrafficLimiter) net.Listener

WrapListener wraps a net.Listener so that accepted connections are automatically wrapped with service-level traffic rate limiting.

func WrapPacketConn

func WrapPacketConn(pc net.PacketConn, lim traffic.TrafficLimiter, key string, opts ...limiter.Option) net.PacketConn

WrapPacketConn wraps a net.PacketConn with traffic rate limiting. Packets exceeding the rate limit are discarded on read or rejected with an error on write.

func WrapReadWriter

func WrapReadWriter(limiter traffic.TrafficLimiter, rw io.ReadWriter, key string, opts ...limiter.Option) io.ReadWriter

WrapReadWriter wraps an io.ReadWriter with traffic rate limiting. If limiter is nil, the original ReadWriter is returned unchanged.

func WrapUDPConn

func WrapUDPConn(pc net.PacketConn, lim traffic.TrafficLimiter, key string, opts ...limiter.Option) udp.Conn

WrapUDPConn wraps a net.PacketConn as a udp.Conn with traffic rate limiting. If pc is nil, nil is returned. If limiter is nil, the original connection is returned unchanged (no-op).

Types

type DroppedPacketCounter added in v0.28.1

type DroppedPacketCounter interface {
	DroppedPackets() int64
}

DroppedPacketCounter is an optional interface implemented by rate-limited packet connections that report the number of packets discarded due to rate limiting.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL