retry

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 4 Imported by: 0

README

retry

该目录只是对外公开的便捷转发层。

  • 面向业务代码提供 gorp/retry 入口
  • 真实实现仍在 framework/*
  • 不在这里承载独立重试实现或新语义

Documentation

Overview

Package retry provides a thin facade for the framework's retry capability. All public functions accept context.Context instead of runtimecontract.Container, resolving the container internally via frameworkcontainer.Resolve(ctx). This keeps business code free of container plumbing — just pass the context you already have and the retry service is looked up automatically.

retry 包提供框架重试能力的薄门面。 所有公开函数接受 context.Context 而非 runtimecontract.Container, 内部通过 frameworkcontainer.Resolve(ctx) 解析容器。 业务代码无需关心容器细节,传入已有的 context 即可自动查找重试服务。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRetryPolicy

func DefaultRetryPolicy() resiliencecontract.RetryPolicy

DefaultRetryPolicy 返回框架内置的默认重试策略。

func Do

func Do(ctx context.Context, fn func() error) error

Do 使用容器中的重试服务执行函数。 内部自动从 ctx 解析容器并获取重试服务,然后调用 retrySvc.Do(ctx, fn)。 如果重试服务未绑定,直接返回解析错误。

Do executes a function with the retry service resolved from ctx. It automatically resolves the container and retry service, then calls retrySvc.Do(ctx, fn). If the retry service is not bound, returns the resolution error directly.

示例:

err := retry.Do(ctx, func() error {
    return callRemote(ctx)
})

func DoWithResult

func DoWithResult(ctx context.Context, fn func() (any, error)) (any, error)

DoWithResult 使用容器中的重试服务执行带返回值的函数。 内部自动从 ctx 解析容器并获取重试服务,然后调用 retrySvc.DoWithResult(ctx, fn)。 如果重试服务未绑定,直接返回解析错误。

DoWithResult executes a function with result using the retry service resolved from ctx. It automatically resolves the container and retry service, then calls retrySvc.DoWithResult(ctx, fn). If the retry service is not bound, returns the resolution error directly.

func GetService added in v0.1.4

func GetService(ctx context.Context) (resiliencecontract.Retry, error)

GetService 从容器获取统一重试服务。 内部通过 ctx 解析容器,再按 RetryKey 查找重试服务实例。 如果容器未初始化或重试服务未绑定,返回错误。

GetService returns the unified retry service from the container resolved via ctx. Returns an error if the container is not initialized or the retry service is not bound.

func IsRetryable

func IsRetryable(ctx context.Context, err error) bool

IsRetryable 判断错误是否可重试。 内部自动从 ctx 解析容器并获取重试服务,然后调用 retrySvc.IsRetryable(err)。 如果重试服务未绑定,返回 false。

IsRetryable reports whether the given error is retryable. It resolves the retry service from ctx and calls retrySvc.IsRetryable(err). If the retry service is not bound, returns false.

func MustGetService added in v0.1.4

func MustGetService(ctx context.Context) resiliencecontract.Retry

MustGetService 从容器获取统一重试服务,失败时 panic。 适用于启动阶段确认服务已绑定的场景,运行时建议使用 GetService。

MustGetService returns the unified retry service from the container resolved via ctx, panicking on failure. Use this in bootstrap code where the service is guaranteed to be bound; prefer GetService in runtime paths.

Types

type Retry

type Retry = resiliencecontract.Retry

Retry 是重试契约的顶层别名,方便业务代码直接引用。

type RetryConfig

type RetryConfig = resiliencecontract.RetryConfig

RetryConfig 是重试配置契约的顶层别名,方便业务代码直接引用。

type RetryPolicy

type RetryPolicy = resiliencecontract.RetryPolicy

RetryPolicy 是重试策略契约的顶层别名,方便业务代码直接引用。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL