base

package
v0.0.0-...-3afba29 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Viper is the global instace of the `viper.Viper`.
	Viper = viper.New()

	// Logger is the global instace of the `zerolog.Logger`.
	Logger = zerolog.New(os.Stderr).With().Timestamp().Logger()

	// Air is the global instace of the `air.Air`.
	Air = air.New()

	// Context is the global instance of the `context.Context`.
	Context context.Context

	// Cron is the global instance of the `cron.Cron`.
	Cron *cron.Cron
)
View Source
var ErrRetryable = errors.New("retryable")

ErrRetryable means an operation is retryable.

View Source
var TZAsiaShanghai = time.FixedZone("Asia/Shanghai", 8*60*60)

TZAsiaShanghai is the "Asia/Shanghai" timezone.

Functions

func Retry

func Retry(
	ctx context.Context,
	f func(ctx context.Context) error,
	retryable func(err error) bool,
	nap time.Duration,
) error

Retry is like the `RetryN`, but at most 100 million retries.

func RetryN

func RetryN(
	ctx context.Context,
	f func(ctx context.Context) error,
	retryable func(err error) bool,
	nap time.Duration,
	n int,
) error

Retry retries the f based on the retryable at most n times. And there is a nap before each retry.

Types

type RetryableError

type RetryableError string

RetryableError is an error indicating that an operation is retryable.

func (RetryableError) Error

func (re RetryableError) Error() string

Error implements the `error`.

func (RetryableError) Is

func (RetryableError) Is(target error) bool

Is reports whether the target is `ErrRetryable`.

Jump to

Keyboard shortcuts

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