tools

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ITools

type ITools interface {
	// Retry 重试工具, 默认一次立即重试 (option is nil)
	Retry(f func() error, option *RetryOption) error

	// SetLaneNameToCtx 设置泳道环境, 只在调试模式下生效
	SetLaneNameToCtx(ctx context.Context, lane string) context.Context

	// ParseErr 转换 err 为有结构的错误,若 err 非系统返回的,则 code 为 ErrCodeDeveloperError
	ParseErr(ctx context.Context, err error) *cExceptions.BaseError

	// MockUserID Mock 用户 ID,比如测试权限场景
	MockUserID(ctx context.Context, userID int64) context.Context

	// GetLogID 获取 logid
	GetLogID(ctx context.Context) string
}

func NewTools

func NewTools(s *structs.AppCtx) ITools

type RetryOption

type RetryOption struct {
	RetryCount    int           // 重试次数
	RetryInterval time.Duration // 重试间隔
}

RetryOption 重试选项

func NewRetryOption

func NewRetryOption(retryCount int, retryDelay time.Duration) *RetryOption

type Tools

type Tools struct {
	// contains filtered or unexported fields
}

func (*Tools) GetLogID added in v0.0.3

func (t *Tools) GetLogID(ctx context.Context) string

func (*Tools) MockUserID added in v0.0.3

func (t *Tools) MockUserID(ctx context.Context, userID int64) context.Context

func (*Tools) ParseErr

func (t *Tools) ParseErr(ctx context.Context, err error) *exceptions.BaseError

func (*Tools) Retry

func (t *Tools) Retry(f func() error, options *RetryOption) error

func (*Tools) SetLaneNameToCtx

func (t *Tools) SetLaneNameToCtx(ctx context.Context, lane string) context.Context

Jump to

Keyboard shortcuts

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