Documentation ¶
Overview ¶
Copyright 2016 Wenhui Shen <www.webx.top>
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 ¶
- func BuildKeys(limiter *config.Limiter, r engine.Request) [][]string
- func LimitByKeys(limiter *config.Limiter, keys []string) *echo.HTTPError
- func LimitByKeysWithCustomTokenBucketTTL(limiter *config.Limiter, keys []string, bucketExpireTTL time.Duration) *echo.HTTPError
- func LimitByRequest(limiter *config.Limiter, r engine.Request) *echo.HTTPError
- func LimitByRequestWithExpiring(limiter *config.Limiter, r engine.Request, bucketExpireTTL time.Duration) *echo.HTTPError
- func LimitHandler(limiter *config.Limiter, bucketExpireTTL ...time.Duration) echo.MiddlewareFunc
- func LimitMiddleware(limiter *config.Limiter, bucketExpireTTL ...time.Duration) echo.MiddlewareFunc
- func New(max int64, ttl time.Duration) *config.Limiter
- func NewExpiringBuckets(max int64, ...) *config.Limiter
- func RemoteIP(ipLookups []string, r engine.Request) string
- func SetResponseHeaders(limiter *config.Limiter, w engine.Response)
- func StringInSlice(sliceString []string, needle string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildKeys ¶
BuildKeys generates a slice of keys to rate-limit by given config and request structs.
func LimitByKeys ¶
LimitByKeys keeps track number of request made by keys separated by pipe. It returns HTTPError when limit is exceeded.
func LimitByKeysWithCustomTokenBucketTTL ¶ added in v1.3.0
func LimitByKeysWithCustomTokenBucketTTL(limiter *config.Limiter, keys []string, bucketExpireTTL time.Duration) *echo.HTTPError
LimitByKeysWithCustomTokenBucketTTL keeps track number of request made by keys separated by pipe. It returns HTTPError when limit is exceeded. User can define a TTL for the key to expire
func LimitByRequest ¶
LimitByRequest builds keys based on http.Request struct, loops through all the keys, and check if any one of them returns HTTPError.
func LimitByRequestWithExpiring ¶ added in v1.3.0
func LimitHandler ¶
func LimitMiddleware ¶
func NewExpiringBuckets ¶ added in v1.3.0
func NewExpiringBuckets(max int64, ttl, bucketDefaultExpirationTTL, bucketExpireJobInterval time.Duration) *config.Limiter
NewExpiringBuckets 带过期时间 @param max 每个周期的最大连接数 @param ttl 周期 @param bucketDefaultExpirationTTL 默认有效时长 @param bucketExpireJobInterval 默认清理周期
func SetResponseHeaders ¶
SetResponseHeaders configures X-Rate-Limit-Limit and X-Rate-Limit-Duration
func StringInSlice ¶
StringInSlice finds needle in a slice of strings.
Types ¶
This section is empty.