tollbooth_negroni

package
v0.0.0-...-605330a Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2016 License: MIT Imports: 4 Imported by: 0

README

tollbooth_negroni

Negroni middleware for rate limiting HTTP requests.

Five Minutes Tutorial

package main

import (
    "github.com/urfave/negroni"
    "github.com/didip/tollbooth"
    "github.com/didip/tollbooth/thirdparty/tollbooth_negroni"
    "net/http"
    "time"
)

func HelloHandler() http.Handler {
    handleFunc := func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("Hello, world!"))
    }

    return http.HandlerFunc(handleFunc)
}

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

    mux := http.NewServeMux()

    mux.Handle("/", negroni.New(
        tollbooth_negroni.LimitHandler(limiter),
        negroni.Wrap(HelloHandler()),
    ))

    n := negroni.Classic()
    n.UseHandler(mux)
    n.Run(":12345")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LimitHandler

func LimitHandler(limiter *config.Limiter) negroni.HandlerFunc

Types

This section is empty.

Jump to

Keyboard shortcuts

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