Documentation ¶
Index ¶
- Constants
- Variables
- func All(actions ...func()) func()
- func C(str interface{}, color string) string
- func ClearScreen() error
- 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 S(tpl string, params ...interface{}) string
- func Sdump(val interface{}) string
- func Sleep(seconds float64)
- func Try(fn func()) (err interface{})
- type Event
- type JSONResult
- type Nil
- type Observable
- type Subscriber
Constants ¶
const Version = "v0.20.7"
Version version the project
Variables ¶
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 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 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 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
type Subscriber ¶ added in v0.19.4
type Subscriber struct { C chan Event // contains filtered or unexported fields }
Subscriber of the observable