Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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 //Bps

ln, 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