Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/puzpuzpuz/tcprate
Minimalistic rate limiter for TCP servers
https://github.com/puzpuzpuz/tcprate
Last synced: about 1 month ago
JSON representation
Minimalistic rate limiter for TCP servers
- Host: GitHub
- URL: https://github.com/puzpuzpuz/tcprate
- Owner: puzpuzpuz
- License: mit
- Created: 2021-06-19T09:20:17.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-06-25T11:26:12.000Z (over 3 years ago)
- Last Synced: 2024-10-12T02:53:19.288Z (2 months ago)
- Language: Go
- Size: 13.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tcprate
Minimalistic rate limiter for TCP servers.
Aimed to follow the public contracts of `net.Listener` and `net.Conn` as much as possible.
## Usage
```go
lis, err := net.Listen("tcp", ":")
if err != nil {
log.Fatal(err)
}
// Wrap the listener.
lim := tcprate.NewListener(lis)
// Set 64 KB/sec global limit and 4 KB/sec limit per connection.
lim.SetLimits(64*1024, 4*1024)
// Now lim can be used as any net.Listener.
// ...
```## Known Limitations
* The rate limit is only applied to outbound server traffic.
* Write errors are ignored when calculating the rate limit.
* Both tests and functionality are minimal.## License
Licensed under MIT.