caller

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const PREFIX_SF_DELIMITER = ":"

Consts

Variables

View Source
var (
	ERR_MISSING_PX_KEY_FOR_CACHE = errors.New("PrefixKey can't be empty if Cache exists")
	ERR_MISSING_PX_KEY_FOR_SF    = errors.New("PrefixKey can't be empty if Singleflight exists")
	ERR_PANIC_AND_RECOVER        = errors.New("panic and recover")
	ERR_TIMEOUT                  = errors.New("timeout")
	ERR_MISSING_WORK_FN          = errors.New("workFn can't be empty")
)

Errors

Functions

This section is empty.

Types

type Caller added in v0.2.0

type Caller interface {
	// Do runs executable functions base on given Config.
	// The key will combine with prefixKey if any.
	// 	CompleteFlow: "GetCache" -> "Singleflight" -> "Breaker" -> "WorkFn" -> "SetCache".
	Do(key string, timeout time.Duration, workFn func() (interface{}, error), nextFn NextFn) (resp interface{}, err error)
	// contains filtered or unexported methods
}

Caller provides list of caller's functions.

func New added in v0.2.0

func New(conf Config) (Caller, error)

New creates caller base on given config.

func NewMust added in v0.3.0

func NewMust(conf Config) Caller

NewMust creates caller base on given config and will panic if there's any err.

type Config added in v0.2.0

type Config struct {
	// PrefixKey represents prefix key of this session
	// and mandatory if using Cache / Singleflight
	// else optional.
	PrefixKey string

	// 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
}

Config provides configuration that will support the workFn.

func (*Config) Do added in v0.2.0

func (conf *Config) Do(
	key string,
	timeout time.Duration,
	workFn func() (interface{}, error),
	nextFn NextFn,
) (resp interface{}, err error)

Do from Caller.

type NextFn added in v0.3.0

type NextFn struct {
	SuccessFn  func() // runs if workFn got success.
	FailFn     func() // runs if workFn got fail.
	TimeoutFn  func() // runs if workFn got timeout.
	BreakerFn  func() // runs if IsErrBerakerOpen=true.
	GetCacheFn func() // runs if GetCache got success.
	SetCacheFn func() // runs if SetCache got success.
}

NextFn provides list of function that will execute, after done in certain situation.

Directories

Path Synopsis
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