Jelajahi Sumber

vendor: golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11

Remove the replace rule, and use the version as specified by (indirect) dependencies:

full diff: https://github.com/golang/time/compare/3af7569d3a1e...f0f3c7e86c11

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 3 tahun lalu
induk
melakukan
368d680dfe
4 mengubah file dengan 28 tambahan dan 23 penghapusan
  1. 0 1
      vendor.mod
  2. 5 1
      vendor.sum
  3. 22 19
      vendor/golang.org/x/time/rate/rate.go
  4. 1 2
      vendor/modules.txt

+ 0 - 1
vendor.mod

@@ -180,7 +180,6 @@ replace (
 	go.opencensus.io => go.opencensus.io v0.22.3
 	go.opencensus.io => go.opencensus.io v0.22.3
 	golang.org/x/net => golang.org/x/net v0.0.0-20210226172049-e18ecbb05110
 	golang.org/x/net => golang.org/x/net v0.0.0-20210226172049-e18ecbb05110
 	golang.org/x/oauth2 => golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
 	golang.org/x/oauth2 => golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
-	golang.org/x/time => golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
 	google.golang.org/api => google.golang.org/api v0.8.0
 	google.golang.org/api => google.golang.org/api v0.8.0
 	google.golang.org/genproto => google.golang.org/genproto v0.0.0-20200227132054-3f1135a288c9
 	google.golang.org/genproto => google.golang.org/genproto v0.0.0-20200227132054-3f1135a288c9
 	google.golang.org/grpc => google.golang.org/grpc v1.27.1
 	google.golang.org/grpc => google.golang.org/grpc v1.27.1

+ 5 - 1
vendor.sum

@@ -652,8 +652,12 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
 golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
 golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s=
+golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
+golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
+golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
+golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 h1:GZokNIeuVkl3aZHJchRrr13WCsols02MLUcz1U9is6M=
+golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

+ 22 - 19
vendor/golang.org/x/time/rate/rate.go

@@ -145,7 +145,6 @@ func (r *Reservation) DelayFrom(now time.Time) time.Duration {
 // Cancel is shorthand for CancelAt(time.Now()).
 // Cancel is shorthand for CancelAt(time.Now()).
 func (r *Reservation) Cancel() {
 func (r *Reservation) Cancel() {
 	r.CancelAt(time.Now())
 	r.CancelAt(time.Now())
-	return
 }
 }
 
 
 // CancelAt indicates that the reservation holder will not perform the reserved action
 // CancelAt indicates that the reservation holder will not perform the reserved action
@@ -186,8 +185,6 @@ func (r *Reservation) CancelAt(now time.Time) {
 			r.lim.lastEvent = prevEvent
 			r.lim.lastEvent = prevEvent
 		}
 		}
 	}
 	}
-
-	return
 }
 }
 
 
 // Reserve is shorthand for ReserveN(time.Now(), 1).
 // Reserve is shorthand for ReserveN(time.Now(), 1).
@@ -309,15 +306,27 @@ func (lim *Limiter) SetBurstAt(now time.Time, newBurst int) {
 // reserveN returns Reservation, not *Reservation, to avoid allocation in AllowN and WaitN.
 // reserveN returns Reservation, not *Reservation, to avoid allocation in AllowN and WaitN.
 func (lim *Limiter) reserveN(now time.Time, n int, maxFutureReserve time.Duration) Reservation {
 func (lim *Limiter) reserveN(now time.Time, n int, maxFutureReserve time.Duration) Reservation {
 	lim.mu.Lock()
 	lim.mu.Lock()
+	defer lim.mu.Unlock()
 
 
 	if lim.limit == Inf {
 	if lim.limit == Inf {
-		lim.mu.Unlock()
 		return Reservation{
 		return Reservation{
 			ok:        true,
 			ok:        true,
 			lim:       lim,
 			lim:       lim,
 			tokens:    n,
 			tokens:    n,
 			timeToAct: now,
 			timeToAct: now,
 		}
 		}
+	} else if lim.limit == 0 {
+		var ok bool
+		if lim.burst >= n {
+			ok = true
+			lim.burst -= n
+		}
+		return Reservation{
+			ok:        ok,
+			lim:       lim,
+			tokens:    lim.burst,
+			timeToAct: now,
+		}
 	}
 	}
 
 
 	now, last, tokens := lim.advance(now)
 	now, last, tokens := lim.advance(now)
@@ -354,7 +363,6 @@ func (lim *Limiter) reserveN(now time.Time, n int, maxFutureReserve time.Duratio
 		lim.last = last
 		lim.last = last
 	}
 	}
 
 
-	lim.mu.Unlock()
 	return r
 	return r
 }
 }
 
 
@@ -367,36 +375,31 @@ func (lim *Limiter) advance(now time.Time) (newNow time.Time, newLast time.Time,
 		last = now
 		last = now
 	}
 	}
 
 
-	// Avoid making delta overflow below when last is very old.
-	maxElapsed := lim.limit.durationFromTokens(float64(lim.burst) - lim.tokens)
-	elapsed := now.Sub(last)
-	if elapsed > maxElapsed {
-		elapsed = maxElapsed
-	}
-
 	// Calculate the new number of tokens, due to time that passed.
 	// Calculate the new number of tokens, due to time that passed.
+	elapsed := now.Sub(last)
 	delta := lim.limit.tokensFromDuration(elapsed)
 	delta := lim.limit.tokensFromDuration(elapsed)
 	tokens := lim.tokens + delta
 	tokens := lim.tokens + delta
 	if burst := float64(lim.burst); tokens > burst {
 	if burst := float64(lim.burst); tokens > burst {
 		tokens = burst
 		tokens = burst
 	}
 	}
-
 	return now, last, tokens
 	return now, last, tokens
 }
 }
 
 
 // durationFromTokens is a unit conversion function from the number of tokens to the duration
 // durationFromTokens is a unit conversion function from the number of tokens to the duration
 // of time it takes to accumulate them at a rate of limit tokens per second.
 // of time it takes to accumulate them at a rate of limit tokens per second.
 func (limit Limit) durationFromTokens(tokens float64) time.Duration {
 func (limit Limit) durationFromTokens(tokens float64) time.Duration {
+	if limit <= 0 {
+		return InfDuration
+	}
 	seconds := tokens / float64(limit)
 	seconds := tokens / float64(limit)
-	return time.Nanosecond * time.Duration(1e9*seconds)
+	return time.Duration(float64(time.Second) * seconds)
 }
 }
 
 
 // tokensFromDuration is a unit conversion function from a time duration to the number of tokens
 // tokensFromDuration is a unit conversion function from a time duration to the number of tokens
 // which could be accumulated during that duration at a rate of limit tokens per second.
 // which could be accumulated during that duration at a rate of limit tokens per second.
 func (limit Limit) tokensFromDuration(d time.Duration) float64 {
 func (limit Limit) tokensFromDuration(d time.Duration) float64 {
-	// Split the integer and fractional parts ourself to minimize rounding errors.
-	// See golang.org/issues/34861.
-	sec := float64(d/time.Second) * float64(limit)
-	nsec := float64(d%time.Second) * float64(limit)
-	return sec + nsec/1e9
+	if limit <= 0 {
+		return 0
+	}
+	return d.Seconds() * float64(limit)
 }
 }

+ 1 - 2
vendor/modules.txt

@@ -858,7 +858,7 @@ golang.org/x/text/secure/bidirule
 golang.org/x/text/transform
 golang.org/x/text/transform
 golang.org/x/text/unicode/bidi
 golang.org/x/text/unicode/bidi
 golang.org/x/text/unicode/norm
 golang.org/x/text/unicode/norm
-# golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 => golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
+# golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11
 ## explicit
 ## explicit
 golang.org/x/time/rate
 golang.org/x/time/rate
 # golang.org/x/tools v0.1.0
 # golang.org/x/tools v0.1.0
@@ -1015,7 +1015,6 @@ gotest.tools/v3/skip
 # go.opencensus.io => go.opencensus.io v0.22.3
 # go.opencensus.io => go.opencensus.io v0.22.3
 # golang.org/x/net => golang.org/x/net v0.0.0-20210226172049-e18ecbb05110
 # golang.org/x/net => golang.org/x/net v0.0.0-20210226172049-e18ecbb05110
 # golang.org/x/oauth2 => golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
 # golang.org/x/oauth2 => golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
-# golang.org/x/time => golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
 # google.golang.org/api => google.golang.org/api v0.8.0
 # google.golang.org/api => google.golang.org/api v0.8.0
 # google.golang.org/genproto => google.golang.org/genproto v0.0.0-20200227132054-3f1135a288c9
 # google.golang.org/genproto => google.golang.org/genproto v0.0.0-20200227132054-3f1135a288c9
 # google.golang.org/grpc => google.golang.org/grpc v1.27.1
 # google.golang.org/grpc => google.golang.org/grpc v1.27.1