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 ¶
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 ¶
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 ¶
func (*Rate) UnmarshalJSON ¶
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