Update README.md

This commit is contained in:
kayos@tcp.direct 2022-07-06 04:41:58 -07:00
parent 78c11c9a7a
commit b45d3f79f5
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
2 changed files with 40 additions and 28 deletions

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021 yunginnanet
Copyright (c) 2021 yunginnanet (kayos@tcp.direct)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,25 +1,23 @@
# Rate5
# Rate5
[![GoDoc](https://godoc.org/github.com/yunginnanet/?status.svg)](https://godoc.org/github.com/yunginnanet/Rate5) [![Go Report Card](https://goreportcard.com/badge/github.com/yunginnanet/Rate5)](https://goreportcard.com/report/github.com/yunginnanet/Rate5) [![Go](https://github.com/yunginnanet/Rate5/actions/workflows/go.yml/badge.svg?branch=main)](https://github.com/yunginnanet/Rate5/actions/workflows/go.yml)
[![codecov](https://codecov.io/gh/yunginnanet/Rate5/branch/main/graph/badge.svg?token=R7WU58G5L7)](https://codecov.io/gh/yunginnanet/Rate5)
A generic ratelimitter for any golang project.
See [the docs](https://godoc.org/github.com/yunginnanet/Rate5) and the [examples](_examples/rated.go) below for more details.
## Short Example
```
import rate5 "github.com/yunginnanet/rate5"
A performant and generic ratelimitter for any golang project.
See [the docs](https://godoc.org/github.com/yunginnanet/Rate5) and the unit tests as well as the below example for more details.
var Rater *rate5.Limiter
## Basic Example
```go
import rate5 "github.com/yunginnanet/rate5"
[...]
var Rater *rate5.Limiter
[...]
type Client struct {
ID string
Conn net.Conn
loggedin bool
}
}
// Rate5 doesn't care where you derive the string used for ratelimiting
func (c Client) UniqueKey() string {
@ -29,24 +27,38 @@ func (c Client) UniqueKey() string {
}
return c.ID
}
func (s *Server) handleTCP(c *Client) {
// Returns true if ratelimited
if Rater.Check(c) {
c.Conn.Write([]byte("too many connections"))
c.Conn.Write([]byte("too many connections"))
c.Conn.Close()
return
}
[...]
```
## In-depth example
[Concurrent TCP Server with Rate5 Ratelimiter](_examples/rated.go)
## To-Do
More Documentation
More To-Dos
~~Test Cases~~
More test cases.
// [...]
}
```
## License
```
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```