utils

package
v0.20.7 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2020 License: MIT Imports: 20 Imported by: 3

Documentation

Index

Constants

View Source
const Version = "v0.20.7"

Version version the project

Variables

View Source
var Stderr = stderr()

Stderr ...

View Source
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 C

func C(str interface{}, color string) string

C color terminal string

func ClearScreen

func ClearScreen() error

ClearScreen ...

func Dump

func Dump(val interface{})

Dump ...

func E

func E(args ...interface{}) []interface{}

E the last arg is error, panic it

func E1

func E1(arg interface{}, err error) interface{}

E1 if the second arg is error panic it, or return the first arg

func Err

func Err(v ...interface{})

Err log to stderr with timestamp and stack trace

func ErrArg

func ErrArg(args ...interface{}) error

ErrArg get the last arg as error

func Log

func Log(v ...interface{})

Log log to stdout with timestamp

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 Noop

func Noop(_ ...interface{})

Noop swallow all args and do nothing

func Pause added in v0.20.5

func Pause()

Pause the execution

func RandBytes

func RandBytes(len int) []byte

RandBytes generate random bytes with specified byte length

func RandString

func RandString(len int) string

RandString generate random string with specified string length

func S

func S(tpl string, params ...interface{}) string

S Template render, the params is key-value pairs

func Sdump

func Sdump(val interface{}) string

Sdump ...

func Sleep added in v0.20.4

func Sleep(seconds float64)

Sleep the execution for specified seconds, such as 2.3 seconds

func Try

func Try(fn func()) (err interface{})

Try try fn with recover, return the panic as value

Types

type Event added in v0.19.4

type Event interface{}

Event of the observale

type JSONResult added in v0.17.0

type JSONResult = *gjson.Result

JSONResult shortcut for gjson.Result

func JSON

func JSON(data interface{}) JSONResult

JSON parse json for easily access the value from json path

type Nil

type Nil struct{}

Nil used to create empty channel

type Observable added in v0.19.4

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

Observable is a thread-safe event helper

func NewObservable added in v0.19.5

func NewObservable() *Observable

NewObservable creates a new observable

func (*Observable) Count added in v0.20.6

func (o *Observable) Count() int

Count returns the number of subscribers

func (*Observable) Publish added in v0.19.4

func (o *Observable) Publish(e Event)

Publish event to all subscribers, no internal goroutine is used, so the publish can block the goroutine. Use goroutine or buffer to prevent the blocking.

func (*Observable) Subscribe added in v0.19.4

func (o *Observable) Subscribe() *Subscriber

Subscribe returns a subscriber to emit events

func (*Observable) Unsubscribe added in v0.19.4

func (o *Observable) Unsubscribe(s *Subscriber)

Unsubscribe from the observable

func (*Observable) Until added in v0.19.4

func (o *Observable) Until(ctx context.Context, check func(Event) bool) (Event, error)

Until check returns true keep waiting

type Subscriber added in v0.19.4

type Subscriber struct {
	C chan Event
	// contains filtered or unexported fields
}

Subscriber of the observable

func (*Subscriber) Filter added in v0.20.7

func (s *Subscriber) Filter(filter func(Event) bool) chan Event

Filter events

Jump to

Keyboard shortcuts

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