1
2
mirror of https://github.com/yunginnanet/Rate5 synced 2024-06-27 01:18:37 +00:00
Go to file
2022-07-06 04:24:50 -07:00
_examples Mild overhaul and testing improvements 2022-07-06 04:05:23 -07:00
.github Update go.yml 2022-03-04 13:43:49 -08:00
.gitignore Actions 2022-03-04 13:33:13 -08: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
LICENSE Add new functions, rename things, add documentation 2021-08-28 07:39:22 -07:00
models.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
ratelimiter.go Fix: data race in strict logic 2022-07-06 04:24:50 -07:00
README.md Update README.md 2022-03-04 13:40:44 -08:00

Rate5

GoDoc Go Report Card Go codecov

A generic ratelimitter for any golang project.
See the docs and the examples below for more details.

Short 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
	}
[...]
    

In-depth example

Concurrent TCP Server with Rate5 Ratelimiter

To-Do

More Documentation
More To-Dos
Test Cases More test cases.