caller

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ERR_INVALID_TIMEOUT    = errors.New("Timeout can't below to 0")
	ERR_MISSING_WORK_FN    = errors.New("WorkFn can't be empty")
	ERR_MISSING_CACHE_KEY  = errors.New("Key can't be empty if Cache exists")
	ERR_MISSING_SF_KEY     = errors.New("Key can't be empty if Singleflight exists")
	ERR_MISSING_BREAKER_FN = errors.New("Breaker can't be empty if BreakerFn exists")
	ERR_PANIC_RECOVER      = errors.New("panic and recover")
	ERR_TIMEOUT            = errors.New("timeout")
)

Errors.

Functions

This section is empty.

Types

type Caller added in v0.2.0

type Caller interface {
	Do() (resp interface{}, err error)
}

func New added in v0.2.0

func New(conf Config) (Caller, error)

New creates caller base on given config.

type Config added in v0.2.0

type Config struct {
	// Key represents keyName of this session
	// and mandatory if using Cache / Singleflight
	// else optional.
	Key string

	// Timeout define the amount of time
	// for WorkFn to finish the task.
	Timeout time.Duration

	// WorkFn is function that will be run.
	WorkFn func() (interface{}, error)

	// Cache store data in memory
	// in a way depending on their method.
	Cache cache.Cache

	// Singleflight make duplicate caller
	// flight in one execution.
	Singleflight singleflight.Singleflight

	// Breaker do go/no-go call to WorkFn
	// under certain threshold.
	Breaker breaker.Breaker

	// SuccessFn runs if WorkFn got success.
	SuccessFn func()

	// FailFn runs if WorkFn got fail.
	FailFn func()

	// TimeoutFn runs if WorkFn got timeout.
	TimeoutFn func()

	// BreakerFn runs if IsErrBerakerOpen=true.
	BreakerFn func()
}

Config provides configuration to execute the work function. Only "WorkFn" and "Timeout" is mandatory else is optional. Some optional required some validation.

Opt: "Cache", "Singleflight", "Breaker", "FailFn", "TimeoutFn", "BreakerFn".

func (*Config) Do added in v0.2.0

func (conf *Config) Do() (resp interface{}, err error)

Do runs executable functions base on given Config.

"WorkFn" and "Timeout" is the main priority.
CompleteFlow: "GetCache" -> "Singleflight" -> "Breaker" -> "WorkFn" -> "SetCache".

Directories

Path Synopsis
go run .
go run .
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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