Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/charconstpointer/netlimit
netlimit allows you to control network io
https://github.com/charconstpointer/netlimit
closer conn golang io net reader throttle wrtier
Last synced: about 22 hours ago
JSON representation
netlimit allows you to control network io
- Host: GitHub
- URL: https://github.com/charconstpointer/netlimit
- Owner: charconstpointer
- License: mit
- Created: 2022-06-09T13:27:05.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-06-16T12:56:30.000Z (over 2 years ago)
- Last Synced: 2024-06-21T11:51:05.683Z (5 months ago)
- Topics: closer, conn, golang, io, net, reader, throttle, wrtier
- Language: Go
- Homepage:
- Size: 58.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# netlimit 🧙🏻♂️
netlimit is a small package that allows you to control bandwitdh usage of `net.Listener` and `net.Conn`, it delivers custom wrapper types around `net.Listener` and `net.Conn` interfaces and util functions like `netlimit.Listen()` and `netlimit.ListenCtx()` to bootstrap the whole process
---
# Usage
Create `netlimit.Listener`
```
//globalLimit limits bandwidth of a listener
globalLimit := 1024 //Bps//localLimit limits bandwidth of a single connection
localLimit := 512 //Bpsln, err := netlisten.Listen(proto, addr, globalLimit, localLimit)
```Use it as you would any other `net.Listener` e.g
```
http.Serve(ln, handler)
```You can tweak limits during runtime
Change local(per connection) limit use
```
err := ln.SetLocalLimit(newLocalLimit)
```Change global(server) limit use
```
err := ln.SetGlobalLimit(newLocalLimit)
```---
# Resources
https://pkg.go.dev/github.com/charconstpointer/netlimit