/
githubmirror
/
client
Обзор
Документация
Войти
/
githubmirror
/
client
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
go/libkb/backoff.go
41 строка
1 KB
zoom-ua
enable gosec (#28775)
08 янв 2026, 19:26
Не верифицирован
08 янв 2026, 19:26
5670f73
Код
Авторство
О чём код?
package libkb // from here: // https://blog.gopheracademy.com/advent-2014/backoff/ import ( "math/rand" "time" ) // BackoffPolicy implements a backoff policy, randomizing its delays // and saturating at the final value in Millis. type BackoffPolicy struct { Millis []int } // BackoffDefault is a backoff policy ranging up to 5 seconds. var BackoffDefault = BackoffPolicy{ []int{0, 10, 10, 100, 100, 500, 500, 3000, 3000, 5000}, } // Duration returns the time duration of the n'th wait cycle in a // backoff policy. This is b.Millis[n], randomized to avoid thundering // herds. func (b BackoffPolicy) Duration(n int) time.Duration { if n >= len(b.Millis) { n = len(b.Millis) - 1 } return time.Duration(jitter(b.Millis[n])) * time.Millisecond } // jitter returns a random integer uniformly distributed in the range // [0.5 * millis .. 1.5 * millis] func jitter(millis int) int { if millis == 0 { return 0 } return millis/2 + rand.Intn(millis) //nolint:gosec // G404: Backoff jitter randomness, not security-critical }