utils

package
v0.19.6 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2020 License: MIT Imports: 17 Imported by: 3

Documentation

Index

Constants

View Source
const Version = "v0.19.6"

Version version the project

Variables

View Source
var Stderr = ansi.NewAnsiStderr()

Stderr ...

View Source
var Stdout = ansi.NewAnsiStdout()

Stdout ...

Functions

func All

func All(actions ...func())

All run all actions concurrently

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 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 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) Publish added in v0.19.4

func (o *Observable) Publish(e Event)

Publish event to all subscribers

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(e Event) bool) (Event, error)

Until check returns true keep waiting

type Subscriber added in v0.19.4

type Subscriber chan Event

Subscriber of the observable

Jump to

Keyboard shortcuts

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