ratelimit

package module
v0.0.0-...-4a305d2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2017 License: BSD-3-Clause Imports: 4 Imported by: 0

README

Rate Limiting Middleware

Build Status GoDoc Coverage Status

Rate limiting middleware for Gem Web framework.

Getting Started

Install

$ go get -u github.com/go-gem/middleware-rate-limit

Example

package main

import (
	"time"
	"log"

	"github.com/go-gem/gem"
	"github.com/go-gem/middleware-rate-limit"
)

func main() {
	router := gem.NewRouter()

	router.GET("/", func(ctx *gem.Context) {
		ctx.HTML(200, "hello")
	}, &gem.HandlerOption{
		Middlewares:[]gem.Middleware{
			ratelimit.New(60, time.Minute),
		},
	})

	log.Println(gem.ListenAndServe(":8080", router.Handler()))
}

Documentation

Overview

Package ratelimit is a HTTP middleware that limit API usage of each user.

Example

package main

import (
	"time"
	"log"

	"github.com/go-gem/gem"
	"github.com/go-gem/middleware-rate-limit"
)

func main() {
	router := gem.NewRouter()

	router.GET("/", func(ctx *gem.Context) {
		ctx.HTML(200, "hello")
	}, &gem.HandlerOption{
		Middlewares:[]gem.Middleware{
			ratelimit.New(60, time.Minute),
		},
	})

	log.Println(gem.ListenAndServe(":8080", router.Handler()))
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

type Limiter struct {
	*config.Limiter
}

Limiter is a HTTP middleware that limit API usage of each user.

func New

func New(max int64, ttl time.Duration) *Limiter

New returns a rate limiter.

maximum number of requests during the given duration.

func (*Limiter) Wrap

func (l *Limiter) Wrap(next gem.Handler) gem.Handler

Wrap implements the Middleware interface.

Jump to

Keyboard shortcuts

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