fix: update lego.
This commit is contained in:
parent
b8b0c8f3e5
commit
8d848c3d60
169 changed files with 12224 additions and 605 deletions
21
vendor/go.uber.org/ratelimit/LICENSE
generated
vendored
Normal file
21
vendor/go.uber.org/ratelimit/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Uber Technologies, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
133
vendor/go.uber.org/ratelimit/internal/clock/clock.go
generated
vendored
Normal file
133
vendor/go.uber.org/ratelimit/internal/clock/clock.go
generated
vendored
Normal file
|
@ -0,0 +1,133 @@
|
|||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
package clock
|
||||
|
||||
// Forked from github.com/andres-erbsen/clock to isolate a missing nap.
|
||||
|
||||
import (
|
||||
"container/heap"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Mock represents a mock clock that only moves forward programmically.
|
||||
// It can be preferable to a real-time clock when testing time-based functionality.
|
||||
type Mock struct {
|
||||
sync.Mutex
|
||||
now time.Time // current time
|
||||
timers Timers // timers
|
||||
}
|
||||
|
||||
// NewMock returns an instance of a mock clock.
|
||||
// The current time of the mock clock on initialization is the Unix epoch.
|
||||
func NewMock() *Mock {
|
||||
return &Mock{now: time.Unix(0, 0)}
|
||||
}
|
||||
|
||||
// Add moves the current time of the mock clock forward by the duration.
|
||||
// This should only be called from a single goroutine at a time.
|
||||
func (m *Mock) Add(d time.Duration) {
|
||||
m.Lock()
|
||||
// Calculate the final time.
|
||||
end := m.now.Add(d)
|
||||
|
||||
for len(m.timers) > 0 && m.now.Before(end) {
|
||||
t := heap.Pop(&m.timers).(*Timer)
|
||||
m.now = t.next
|
||||
m.Unlock()
|
||||
t.Tick()
|
||||
m.Lock()
|
||||
}
|
||||
|
||||
m.Unlock()
|
||||
// Give a small buffer to make sure the other goroutines get handled.
|
||||
nap()
|
||||
}
|
||||
|
||||
// Timer produces a timer that will emit a time some duration after now.
|
||||
func (m *Mock) Timer(d time.Duration) *Timer {
|
||||
ch := make(chan time.Time)
|
||||
t := &Timer{
|
||||
C: ch,
|
||||
c: ch,
|
||||
mock: m,
|
||||
next: m.now.Add(d),
|
||||
}
|
||||
m.addTimer(t)
|
||||
return t
|
||||
}
|
||||
|
||||
func (m *Mock) addTimer(t *Timer) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
heap.Push(&m.timers, t)
|
||||
}
|
||||
|
||||
// After produces a channel that will emit the time after a duration passes.
|
||||
func (m *Mock) After(d time.Duration) <-chan time.Time {
|
||||
return m.Timer(d).C
|
||||
}
|
||||
|
||||
// AfterFunc waits for the duration to elapse and then executes a function.
|
||||
// A Timer is returned that can be stopped.
|
||||
func (m *Mock) AfterFunc(d time.Duration, f func()) *Timer {
|
||||
t := m.Timer(d)
|
||||
go func() {
|
||||
<-t.c
|
||||
f()
|
||||
}()
|
||||
nap()
|
||||
return t
|
||||
}
|
||||
|
||||
// Now returns the current wall time on the mock clock.
|
||||
func (m *Mock) Now() time.Time {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
return m.now
|
||||
}
|
||||
|
||||
// Sleep pauses the goroutine for the given duration on the mock clock.
|
||||
// The clock must be moved forward in a separate goroutine.
|
||||
func (m *Mock) Sleep(d time.Duration) {
|
||||
<-m.After(d)
|
||||
}
|
||||
|
||||
// Timer represents a single event.
|
||||
type Timer struct {
|
||||
C <-chan time.Time
|
||||
c chan time.Time
|
||||
next time.Time // next tick time
|
||||
mock *Mock // mock clock
|
||||
}
|
||||
|
||||
func (t *Timer) Next() time.Time { return t.next }
|
||||
|
||||
func (t *Timer) Tick() {
|
||||
select {
|
||||
case t.c <- t.next:
|
||||
default:
|
||||
}
|
||||
nap()
|
||||
}
|
||||
|
||||
// Sleep momentarily so that other goroutines can process.
|
||||
func nap() { time.Sleep(1 * time.Millisecond) }
|
34
vendor/go.uber.org/ratelimit/internal/clock/interface.go
generated
vendored
Normal file
34
vendor/go.uber.org/ratelimit/internal/clock/interface.go
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
package clock
|
||||
|
||||
import "time"
|
||||
|
||||
// Clock represents an interface to the functions in the standard library time
|
||||
// package. Two implementations are available in the clock package. The first
|
||||
// is a real-time clock which simply wraps the time package's functions. The
|
||||
// second is a mock clock which will only make forward progress when
|
||||
// programmatically adjusted.
|
||||
type Clock interface {
|
||||
AfterFunc(d time.Duration, f func())
|
||||
Now() time.Time
|
||||
Sleep(d time.Duration)
|
||||
}
|
42
vendor/go.uber.org/ratelimit/internal/clock/real.go
generated
vendored
Normal file
42
vendor/go.uber.org/ratelimit/internal/clock/real.go
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
package clock
|
||||
|
||||
import "time"
|
||||
|
||||
// clock implements a real-time clock by simply wrapping the time package functions.
|
||||
type clock struct{}
|
||||
|
||||
// New returns an instance of a real-time clock.
|
||||
func New() Clock {
|
||||
return &clock{}
|
||||
}
|
||||
|
||||
func (c *clock) After(d time.Duration) <-chan time.Time { return time.After(d) }
|
||||
|
||||
func (c *clock) AfterFunc(d time.Duration, f func()) {
|
||||
// TODO maybe return timer interface
|
||||
time.AfterFunc(d, f)
|
||||
}
|
||||
|
||||
func (c *clock) Now() time.Time { return time.Now() }
|
||||
|
||||
func (c *clock) Sleep(d time.Duration) { time.Sleep(d) }
|
44
vendor/go.uber.org/ratelimit/internal/clock/timers.go
generated
vendored
Normal file
44
vendor/go.uber.org/ratelimit/internal/clock/timers.go
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
package clock
|
||||
|
||||
// timers represents a list of sortable timers.
|
||||
type Timers []*Timer
|
||||
|
||||
func (ts Timers) Len() int { return len(ts) }
|
||||
|
||||
func (ts Timers) Swap(i, j int) {
|
||||
ts[i], ts[j] = ts[j], ts[i]
|
||||
}
|
||||
|
||||
func (ts Timers) Less(i, j int) bool {
|
||||
return ts[i].Next().Before(ts[j].Next())
|
||||
}
|
||||
|
||||
func (ts *Timers) Push(t interface{}) {
|
||||
*ts = append(*ts, t.(*Timer))
|
||||
}
|
||||
|
||||
func (ts *Timers) Pop() interface{} {
|
||||
t := (*ts)[len(*ts)-1]
|
||||
*ts = (*ts)[:len(*ts)-1]
|
||||
return t
|
||||
}
|
140
vendor/go.uber.org/ratelimit/ratelimit.go
generated
vendored
Normal file
140
vendor/go.uber.org/ratelimit/ratelimit.go
generated
vendored
Normal file
|
@ -0,0 +1,140 @@
|
|||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
package ratelimit // import "go.uber.org/ratelimit"
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.uber.org/ratelimit/internal/clock"
|
||||
)
|
||||
|
||||
// Note: This file is inspired by:
|
||||
// https://github.com/prashantv/go-bench/blob/master/ratelimit
|
||||
|
||||
// Limiter is used to rate-limit some process, possibly across goroutines.
|
||||
// The process is expected to call Take() before every iteration, which
|
||||
// may block to throttle the goroutine.
|
||||
type Limiter interface {
|
||||
// Take should block to make sure that the RPS is met.
|
||||
Take() time.Time
|
||||
}
|
||||
|
||||
// Clock is the minimum necessary interface to instantiate a rate limiter with
|
||||
// a clock or mock clock, compatible with clocks created using
|
||||
// github.com/andres-erbsen/clock.
|
||||
type Clock interface {
|
||||
Now() time.Time
|
||||
Sleep(time.Duration)
|
||||
}
|
||||
|
||||
type limiter struct {
|
||||
sync.Mutex
|
||||
last time.Time
|
||||
sleepFor time.Duration
|
||||
perRequest time.Duration
|
||||
maxSlack time.Duration
|
||||
clock Clock
|
||||
}
|
||||
|
||||
// Option configures a Limiter.
|
||||
type Option func(l *limiter)
|
||||
|
||||
// New returns a Limiter that will limit to the given RPS.
|
||||
func New(rate int, opts ...Option) Limiter {
|
||||
l := &limiter{
|
||||
perRequest: time.Second / time.Duration(rate),
|
||||
maxSlack: -10 * time.Second / time.Duration(rate),
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(l)
|
||||
}
|
||||
if l.clock == nil {
|
||||
l.clock = clock.New()
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
// WithClock returns an option for ratelimit.New that provides an alternate
|
||||
// Clock implementation, typically a mock Clock for testing.
|
||||
func WithClock(clock Clock) Option {
|
||||
return func(l *limiter) {
|
||||
l.clock = clock
|
||||
}
|
||||
}
|
||||
|
||||
// WithoutSlack is an option for ratelimit.New that initializes the limiter
|
||||
// without any initial tolerance for bursts of traffic.
|
||||
var WithoutSlack Option = withoutSlackOption
|
||||
|
||||
func withoutSlackOption(l *limiter) {
|
||||
l.maxSlack = 0
|
||||
}
|
||||
|
||||
// Take blocks to ensure that the time spent between multiple
|
||||
// Take calls is on average time.Second/rate.
|
||||
func (t *limiter) Take() time.Time {
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
|
||||
now := t.clock.Now()
|
||||
|
||||
// If this is our first request, then we allow it.
|
||||
if t.last.IsZero() {
|
||||
t.last = now
|
||||
return t.last
|
||||
}
|
||||
|
||||
// sleepFor calculates how much time we should sleep based on
|
||||
// the perRequest budget and how long the last request took.
|
||||
// Since the request may take longer than the budget, this number
|
||||
// can get negative, and is summed across requests.
|
||||
t.sleepFor += t.perRequest - now.Sub(t.last)
|
||||
|
||||
// We shouldn't allow sleepFor to get too negative, since it would mean that
|
||||
// a service that slowed down a lot for a short period of time would get
|
||||
// a much higher RPS following that.
|
||||
if t.sleepFor < t.maxSlack {
|
||||
t.sleepFor = t.maxSlack
|
||||
}
|
||||
|
||||
// If sleepFor is positive, then we should sleep now.
|
||||
if t.sleepFor > 0 {
|
||||
t.clock.Sleep(t.sleepFor)
|
||||
t.last = now.Add(t.sleepFor)
|
||||
t.sleepFor = 0
|
||||
} else {
|
||||
t.last = now
|
||||
}
|
||||
|
||||
return t.last
|
||||
}
|
||||
|
||||
type unlimited struct{}
|
||||
|
||||
// NewUnlimited returns a RateLimiter that is not limited.
|
||||
func NewUnlimited() Limiter {
|
||||
return unlimited{}
|
||||
}
|
||||
|
||||
func (unlimited) Take() time.Time {
|
||||
return time.Now()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue