Go to file
kayos@tcp.direct b45d3f79f5
Update README.md
2022-07-06 04:42:37 -07:00
.github Update go.yml 2022-03-04 13:43:49 -08:00
.gitignore Actions 2022-03-04 13:33:13 -08:00
LICENSE Update README.md 2022-07-06 04:42:37 -07:00
README.md Update README.md 2022-07-06 04:42:37 -07:00
go.mod Mild overhaul and testing improvements 2022-07-06 04:05:23 -07:00
go.sum initial commit 2021-08-27 23:22:25 -07:00
models.go Fix: data race in strict logic 2022-07-06 04:24:50 -07:00
ratelimiter.go Fix: data race in strict logic 2022-07-06 04:24:50 -07:00
ratelimiter_test.go Fix: data race in strict logic 2022-07-06 04:24:50 -07:00

Rate5

GoDoc Go Report Card Go codecov

A performant and generic ratelimitter for any golang project. See the docs and the unit tests as well as the below example for more details.

Basic Example

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 {
        if !c.loggedin {
                host, _, _ := net.SplitHostPort(c.Conn.RemoteAddr().String())
                return host
        }
        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.Close()
		return
	}
// [...]
}

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.