Skip to content

Latest commit

 

History

History
33 lines (23 loc) · 602 Bytes

README.md

File metadata and controls

33 lines (23 loc) · 602 Bytes

tollbooth_chi

Chi middleware for rate limiting HTTP requests.

Five Minutes Tutorial

package main

import (
    "github.com/didip/tollbooth"
    "github.com/didip/tollbooth_chi"
    "github.com/pressly/chi"
    "net/http"
    "time"
)

func main() {
    // Create a limiter struct.
    limiter := tollbooth.NewLimiter(1, nil)

    r := chi.NewRouter()

    r.Use(tollbooth_chi.LimitHandler(limiter))

    r.Get("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("Hello, world!"))
    })

    http.ListenAndServe(":12345", r)
}