You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Go to file
kayos 9de4224b56
Merge pull request #5 from yunginnanet/dependabot/github_actions/github/codeql-action-2
2 months ago
.github Merge pull request #5 from yunginnanet/dependabot/github_actions/github/codeql-action-2 2 months ago
.gitignore Actions 1 year ago
LICENSE Update README.md 11 months ago
README.md Update README.md 5 months ago
debug.go Fix: only print if we enabled 5 months ago
go.mod Mild overhaul and testing improvements 11 months ago
go.sum initial commit 2 years ago
models.go Feat: Stringer Identity + Optimize 6 months ago
ratelimiter.go Feat: Stringer Identity + Optimize 6 months ago
ratelimiter_test.go Fix coverage 5 months ago

README.md

Rate5

GoDoc Go Report Card Go codecov five

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.