mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
update go-limiter to v0.3.0 (#9697)
This commit is contained in:
2
go.mod
2
go.mod
@@ -131,7 +131,7 @@ require (
|
||||
github.com/ryanuber/go-glob v1.0.0
|
||||
github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec
|
||||
github.com/sasha-s/go-deadlock v0.2.0
|
||||
github.com/sethvargo/go-limiter v0.2.3
|
||||
github.com/sethvargo/go-limiter v0.3.0
|
||||
github.com/shirou/gopsutil v2.20.6-0.20200630091542-01afd763e6c0+incompatible
|
||||
github.com/stretchr/testify v1.5.1
|
||||
github.com/tidwall/pretty v1.0.1 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -853,6 +853,8 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUt
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/sethvargo/go-limiter v0.2.3 h1:xgphnEi/Ga/1JMU3Y4Zc8PzyOes4fci/wWwHN6alcqg=
|
||||
github.com/sethvargo/go-limiter v0.2.3/go.mod h1:C0kbSFbiriE5k2FFOe18M1YZbAR2Fiwf72uGu0CXCcU=
|
||||
github.com/sethvargo/go-limiter v0.3.0 h1:yRMc+Qs2yqw6YJp6UxrO2iUs6DOSq4zcnljbB7/rMns=
|
||||
github.com/sethvargo/go-limiter v0.3.0/go.mod h1:C0kbSFbiriE5k2FFOe18M1YZbAR2Fiwf72uGu0CXCcU=
|
||||
github.com/shirou/gopsutil v2.20.6-0.20200630091542-01afd763e6c0+incompatible h1:IYOqH6sML3rQGNVEQ5foLtpDt4TeW8PIUBuI9f8itkI=
|
||||
github.com/shirou/gopsutil v2.20.6-0.20200630091542-01afd763e6c0+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 h1:pntxY8Ary0t43dCZ5dqY4YTJCObLY1kIXl0uzMv+7DE=
|
||||
|
||||
19
vendor/github.com/sethvargo/go-limiter/internal/fasttime/fasttime.go
generated
vendored
Normal file
19
vendor/github.com/sethvargo/go-limiter/internal/fasttime/fasttime.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// +build !windows
|
||||
|
||||
// Package fasttime gets wallclock time, but super fast.
|
||||
package fasttime
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
//go:noescape
|
||||
//go:linkname walltime runtime.walltime
|
||||
func walltime() (int64, int32)
|
||||
|
||||
// Now returns a monotonic clock value. The actual value will differ across
|
||||
// systems, but that's okay because we generally only care about the deltas.
|
||||
func Now() uint64 {
|
||||
x, y := walltime()
|
||||
return uint64(x)*1e9 + uint64(y)
|
||||
}
|
||||
11
vendor/github.com/sethvargo/go-limiter/internal/fasttime/fasttime_windows.go
generated
vendored
Normal file
11
vendor/github.com/sethvargo/go-limiter/internal/fasttime/fasttime_windows.go
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
// +build windows
|
||||
|
||||
package fasttime
|
||||
|
||||
import "time"
|
||||
|
||||
// Now returns a monotonic clock value. On Windows, no such clock exists, so we
|
||||
// fallback to time.Now().
|
||||
func Now() uint64 {
|
||||
return uint64(time.Now().UnixNano())
|
||||
}
|
||||
18
vendor/github.com/sethvargo/go-limiter/memorystore/store.go
generated
vendored
18
vendor/github.com/sethvargo/go-limiter/memorystore/store.go
generated
vendored
@@ -8,6 +8,7 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/sethvargo/go-limiter"
|
||||
"github.com/sethvargo/go-limiter/internal/fasttime"
|
||||
)
|
||||
|
||||
var _ limiter.Store = (*store)(nil)
|
||||
@@ -181,7 +182,7 @@ func (s *store) purge() {
|
||||
}
|
||||
|
||||
s.dataLock.Lock()
|
||||
now := fastnow()
|
||||
now := fasttime.Now()
|
||||
for k, b := range s.data {
|
||||
lastTick := (*bucketState)(atomic.LoadPointer(&b.bucketState)).lastTick
|
||||
lastTime := b.startTime + (lastTick * uint64(b.interval))
|
||||
@@ -231,7 +232,7 @@ type bucketState struct {
|
||||
// newBucket creates a new bucket from the given tokens and interval.
|
||||
func newBucket(tokens uint64, interval time.Duration, rate float64) *bucket {
|
||||
b := &bucket{
|
||||
startTime: fastnow(),
|
||||
startTime: fasttime.Now(),
|
||||
maxTokens: tokens,
|
||||
interval: interval,
|
||||
fillRate: rate,
|
||||
@@ -250,7 +251,7 @@ func newBucket(tokens uint64, interval time.Duration, rate float64) *bucket {
|
||||
func (b *bucket) take() (uint64, uint64, uint64, bool) {
|
||||
// Capture the current request time, current tick, and amount of time until
|
||||
// the bucket resets.
|
||||
now := fastnow()
|
||||
now := fasttime.Now()
|
||||
currTick := tick(b.startTime, now, b.interval)
|
||||
next := b.startTime + ((currTick + 1) * uint64(b.interval))
|
||||
|
||||
@@ -313,14 +314,3 @@ func availableTokens(last, curr, max uint64, fillRate float64) uint64 {
|
||||
func tick(start, curr uint64, interval time.Duration) uint64 {
|
||||
return (curr - start) / uint64(interval)
|
||||
}
|
||||
|
||||
//go:noescape
|
||||
//go:linkname walltime runtime.walltime
|
||||
func walltime() (int64, int32)
|
||||
|
||||
// fastnow returns a monotonic clock value. The actual value will differ across
|
||||
// systems, but that's okay because we generally only care about the deltas.
|
||||
func fastnow() uint64 {
|
||||
x, y := walltime()
|
||||
return uint64(x)*1e9 + uint64(y)
|
||||
}
|
||||
|
||||
3
vendor/modules.txt
vendored
3
vendor/modules.txt
vendored
@@ -801,9 +801,10 @@ github.com/samuel/go-zookeeper/zk
|
||||
github.com/sasha-s/go-deadlock
|
||||
# github.com/satori/go.uuid v1.2.0
|
||||
github.com/satori/go.uuid
|
||||
# github.com/sethvargo/go-limiter v0.2.3
|
||||
# github.com/sethvargo/go-limiter v0.3.0
|
||||
github.com/sethvargo/go-limiter
|
||||
github.com/sethvargo/go-limiter/httplimit
|
||||
github.com/sethvargo/go-limiter/internal/fasttime
|
||||
github.com/sethvargo/go-limiter/memorystore
|
||||
# github.com/shirou/gopsutil v2.20.6-0.20200630091542-01afd763e6c0+incompatible
|
||||
github.com/shirou/gopsutil/cpu
|
||||
|
||||
Reference in New Issue
Block a user