Documentation ¶
Index ¶
- Constants
- Variables
- func All(actions ...func()) func()
- func C(str interface{}, color string) string
- func ClearScreen() error
- func DefaultBackoff(interval time.Duration) time.Duration
- func Dump(val interface{})
- func E(args ...interface{}) []interface{}
- func E1(arg interface{}, err error) interface{}
- func Err(v ...interface{})
- func ErrArg(args ...interface{}) error
- func Log(v ...interface{})
- func MustToJSON(data interface{}) string
- func MustToJSONBytes(data interface{}) []byte
- func Noop(_ ...interface{})
- func Pause()
- func RandBytes(len int) []byte
- func RandString(len int) string
- func Retry(ctx context.Context, s Sleeper, fn func() (stop bool, err error)) error
- func S(tpl string, params ...interface{}) string
- func Sdump(val interface{}) string
- func Sleep(seconds float64)
- func Try(fn func()) (err interface{})
- type ErrInjector
- type JSONResult
- type Nil
- type Sleeper
Constants ¶
const Version = "v0.25.5"
Version version the project
Variables ¶
var ErrMaxSleepCount = errors.New("max sleep count")
ErrMaxSleepCount ...
var Stderr = stderr()
Stderr ...
var Stdout = stdout()
Stdout ...
Functions ¶
func All ¶
func All(actions ...func()) func()
All run all actions concurrently, returns the wait function for all actions.
func DefaultBackoff ¶ added in v0.21.0
DefaultBackoff algorithm: A(n) = A(n-1) * random[1.9, 2.1)
func E1 ¶
func E1(arg interface{}, err error) interface{}
E1 if the second arg is error panic it, or return the first arg
func MustToJSON ¶ added in v0.16.3
func MustToJSON(data interface{}) string
MustToJSON encode data to json string
func MustToJSONBytes ¶ added in v0.16.3
func MustToJSONBytes(data interface{}) []byte
MustToJSONBytes encode data to json bytes
func RandString ¶
RandString generate random string with specified string length
Types ¶
type ErrInjector ¶ added in v0.21.1
type ErrInjector struct {
// contains filtered or unexported fields
}
ErrInjector let you easily mock error for testing
func (*ErrInjector) CountInject ¶ added in v0.21.1
func (e *ErrInjector) CountInject(times int, err error)
CountInject inject err after E is called with specified times
func (*ErrInjector) Inject ¶ added in v0.21.1
func (e *ErrInjector) Inject(fn func(error) error)
Inject the fn and enable the enjection, call it with nil to disable injection
type JSONResult ¶ added in v0.17.0
JSONResult shortcut for gjson.Result
func JSON ¶
func JSON(data interface{}) JSONResult
JSON parse json for easily access the value from json path
type Sleeper ¶ added in v0.21.0
Sleeper sleeps for sometime, returns the reason to wake, if ctx is done release resource
func BackoffSleeper ¶ added in v0.21.0
func BackoffSleeper(init, maxInterval time.Duration, algorithm func(time.Duration) time.Duration) Sleeper
BackoffSleeper returns a sleeper that sleeps in a backoff manner every time get called. If algorithm is nil, DefaultBackoff will be used. Set interval and maxInterval to the same value to make it a constant interval sleeper. If maxInterval is not greater than 0, it will wake immediately.
func CountSleeper ¶ added in v0.21.0
CountSleeper wake when counts to max and return
func MergeSleepers ¶ added in v0.21.0
MergeSleepers into one, wakes when first sleeper wakes. Such as you want to poll to check if wifi is connected, when you poll you also want to do do the check whenever wifi driver is enabled, then you can merge BackoffSleeper and ChannelSleeper to achieve it.