config

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2017 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Overview

Package config provides data structure to configure rate-limiter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

type Limiter struct {
	// HTTP message when limit is reached.
	Message string

	// Content-Type for Message
	MessageContentType string

	// HTTP status code when limit is reached.
	StatusCode int

	// Maximum number of requests to limit per duration.
	Max int64

	// Duration of rate-limiter.
	TTL time.Duration

	// List of places to look up IP address.
	// Default is "RemoteAddr", "X-Forwarded-For", "X-Real-IP".
	// You can rearrange the order as you like.
	IPLookups []string

	// List of HTTP Methods to limit (GET, POST, PUT, etc.).
	// Empty means limit all methods.
	Methods []string

	// List of HTTP headers to limit.
	// Empty means skip headers checking.
	Headers map[string][]string

	// List of basic auth usernames to limit.
	BasicAuthUsers []string

	sync.RWMutex
	// contains filtered or unexported fields
}

Limiter is a config struct to limit a particular request handler.

func NewLimiter

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

NewLimiter is a constructor for Limiter.

func (*Limiter) LimitReached

func (l *Limiter) LimitReached(key string) bool

LimitReached returns a bool indicating if the Bucket identified by key ran out of tokens.

Jump to

Keyboard shortcuts

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