No Description

kayos@tcp.direct 1af4e1579e Update README 2 weeks ago
.github 274199f780 Create go.yml 3 weeks ago
_examples 5aea254233 Fix: Major bug with Peek. New: test cases 3 weeks ago
LICENSE 151f1bd64e Add new functions, rename things, add documentation 1 month ago
README.md 1af4e1579e Update README 2 weeks ago
go.mod ad4fd544fc initial commit 1 month ago
go.sum ad4fd544fc initial commit 1 month ago
models.go aeea9560c8 bugfix 3 weeks ago
ratelimiter.go 81f043def7 Testing: concurrency safety 2 weeks ago
ratelimiter_test.go 81f043def7 Testing: concurrency safety 2 weeks ago

README.md

Rate5

GoDoc Go Report Card Go

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.