limiter

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Copyright 2015 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2015 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2015 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	DefaultMaxNumberOfUsers = 100000
	DefaultRate             = 100000000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionsLimiter

type ConnectionsLimiter struct {
	*connlimit.ConnLimiter
	*sync.Mutex
	// contains filtered or unexported fields
}

func NewConnectionsLimiter

func NewConnectionsLimiter(config LimiterConfig) (*ConnectionsLimiter, error)

func (*ConnectionsLimiter) AcquireConnection

func (l *ConnectionsLimiter) AcquireConnection(token string) error

func (*ConnectionsLimiter) ReleaseConnection

func (l *ConnectionsLimiter) ReleaseConnection(token string)

func (*ConnectionsLimiter) WrapHandle

func (l *ConnectionsLimiter) WrapHandle(h http.Handler)

Add connection limiter to the handle

type Limiter

type Limiter struct {
	// both limiters implement http.Handle
	*ConnectionsLimiter
	// contains filtered or unexported fields
}

func NewLimiter

func NewLimiter(config LimiterConfig) (*Limiter, error)

func (*Limiter) RegisterRequest

func (l *Limiter) RegisterRequest(token string) error

func (*Limiter) WrapHandle

func (l *Limiter) WrapHandle(h http.Handler)

Add limiter to the handle

type LimiterConfig

type LimiterConfig struct {
	Rates            []Rate
	MaxConnections   int64 `yaml:"max_connections" json:"max_connections"`
	MaxNumberOfUsers int   `yaml:"max_users" json:"max_users"`
}

func (*LimiterConfig) SetEnv

func (l *LimiterConfig) SetEnv(v string) error

SetEnv reads LimiterConfig from JSON string

type Rate

type Rate struct {
	Period  time.Duration
	Average int64
	Burst   int64
}

func (*Rate) UnmarshalJSON

func (r *Rate) UnmarshalJSON(value []byte) error

type RateLimiter

type RateLimiter struct {
	*ratelimit.TokenLimiter

	*sync.Mutex
	// contains filtered or unexported fields
}

func NewRateLimiter

func NewRateLimiter(config LimiterConfig) (*RateLimiter, error)

func (*RateLimiter) RegisterRequest

func (l *RateLimiter) RegisterRequest(token string) error

RegisterRequest increases number of requests for the provided token Returns error if there are too many requests with the provided token

func (*RateLimiter) WrapHandle

func (l *RateLimiter) WrapHandle(h http.Handler)

Add rate limiter to the handle

Jump to

Keyboard shortcuts

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