Throttle throttles the method for each incoming request. The throttle algorithm is based on token bucket implementation: http://en.wikipedia.org/wiki/Token_bucket. Rate determines the number of request which are allowed per frequency. Example: A capacity of 50 and fillInterval of two seconds means t
(fillInterval time.Duration, capacity int64)
| 109 | // example to have throttle with 30 req/second, you need to have a fillinterval |
| 110 | // of 33.33 milliseconds. |
| 111 | func (m *Method) Throttle(fillInterval time.Duration, capacity int64) *Method { |
| 112 | // don't do anything if the bucket is initialized already |
| 113 | if m.bucket != nil { |
| 114 | return m |
| 115 | } |
| 116 | |
| 117 | m.bucket = ratelimit.NewBucket( |
| 118 | fillInterval, // interval |
| 119 | capacity, // token per interval |
| 120 | ) |
| 121 | |
| 122 | return m |
| 123 | } |
| 124 | |
| 125 | // PreHandler adds a new kite handler which is executed before the method. |
| 126 | func (m *Method) PreHandle(handler Handler) *Method { |
no outgoing calls