command
Version:
v0.9.0
Opens a new window with list of versions in this module.
Published: Aug 19, 2026
License: Apache-2.0
Opens a new window with license information.
Imports: 5
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
backoff —— 退避重试
演示 pkg/resilience/backoff 的指数退避序列、Retry 自动重试与 RetryIf 按错误类型决定是否继续。
运行
go run ./examples/backoff
说明
Duration(attempt) 计算第 N 次重试等待时间(base × factor,带上限 max)。
Retry 包住可能失败的操作,示例模拟第 3 次才成功。
RetryIf 传入 retryable(err) 谓词;遇到 400 bad request 等不可重试错误立即停止。
- 生产常用
JitterFull 抖动避免惊群;示例用 JitterNone 便于看清序列。
Documentation
¶
backoff 示例:指数退避 + 抖动重试。
演示 pkg/backoff:Duration(attempt) 计算退避序列、Retry 包住可能失败的操作、
RetryIf 对特定错误不重试。
Source Files
¶
Click to show internal directories.
Click to hide internal directories.