mirror of https://github.com/yunginnanet/Rate5
Update README.md
This commit is contained in:
parent
78c11c9a7a
commit
b45d3f79f5
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
66
README.md
66
README.md
|
@ -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)
|
[![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)
|
[![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
|
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.
|
||||||
import rate5 "github.com/yunginnanet/rate5"
|
|
||||||
|
|
||||||
var Rater *rate5.Limiter
|
## Basic Example
|
||||||
|
```go
|
||||||
|
import rate5 "github.com/yunginnanet/rate5"
|
||||||
|
|
||||||
[...]
|
var Rater *rate5.Limiter
|
||||||
|
|
||||||
|
[...]
|
||||||
type Client struct {
|
type Client struct {
|
||||||
ID string
|
ID string
|
||||||
Conn net.Conn
|
Conn net.Conn
|
||||||
|
|
||||||
loggedin bool
|
loggedin bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rate5 doesn't care where you derive the string used for ratelimiting
|
// Rate5 doesn't care where you derive the string used for ratelimiting
|
||||||
func (c Client) UniqueKey() string {
|
func (c Client) UniqueKey() string {
|
||||||
|
@ -29,24 +27,38 @@ func (c Client) UniqueKey() string {
|
||||||
}
|
}
|
||||||
return c.ID
|
return c.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleTCP(c *Client) {
|
func (s *Server) handleTCP(c *Client) {
|
||||||
// Returns true if ratelimited
|
// Returns true if ratelimited
|
||||||
if Rater.Check(c) {
|
if Rater.Check(c) {
|
||||||
c.Conn.Write([]byte("too many connections"))
|
c.Conn.Write([]byte("too many connections"))
|
||||||
c.Conn.Close()
|
c.Conn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
[...]
|
// [...]
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## In-depth example
|
## License
|
||||||
|
|
||||||
[Concurrent TCP Server with Rate5 Ratelimiter](_examples/rated.go)
|
```
|
||||||
|
MIT License
|
||||||
## To-Do
|
|
||||||
More Documentation
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
More To-Dos
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
~~Test Cases~~
|
in the Software without restriction, including without limitation the rights
|
||||||
More test cases.
|
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.
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in New Issue