tollbooth_httprouter

package
v0.0.0-...-be7d489 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2015 License: MIT Imports: 4 Imported by: 0

README

tollbooth_httprouter

httprouter middleware for rate limiting HTTP requests.

Five Minutes Tutorial

package main

import (
    "time"
    "log"

    "github.com/didip/tollbooth"
    "github.com/didip/tollbooth/thirdparty/tollbooth_httprouter"
    "github.com/julienschmidt/httprouter"
)

Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
    fmt.Fprint(w, "Welcome!\n")
}

func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
    fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))
}

func main() {
    router := httprouter.New()

    // Create a limiter struct.
    limiter := tollbooth.NewLimiter(1, time.Second)

    // Index route without limiting.
    router.GET("/", Index)

    // Hello route with limiting.
    router.GET("/hello/:name",
        tollbooth_httprouter.LimitHandler(Hello, limiter),
    )

    log.Fatal(http.ListenAndServe(":8080", router))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LimitHandler

func LimitHandler(handler httprouter.Handle, limiter *config.Limiter) httprouter.Handle

RateLimit is a rate limiting middleware

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL