utils

package
v0.0.0-...-78a648b Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const JsonExt = ".json"

Variables

View Source
var ErrIgnore = errors.New("error ignore")

Functions

func CacheTime

func CacheTime() string

CacheTime returns a time cache in seconds. we use a cache to reduce the format

func Dup

func Dup(from, to int) error

func GenerateUUID

func GenerateUUID() string

GenerateUUID generates an uuid https://tools.ietf.org/html/rfc4122 crypto.rand use getrandom(2) or /dev/urandom It is maybe occur an error due to system error panic if an error occurred

func GoWithRecover

func GoWithRecover(handler func(), recoverHandler func(r interface{}))

GoWithRecover wraps a `go func()` with recover()

func ReadJsonFile

func ReadJsonFile(file string, v interface{}) error

ReadJsonFile reads a json into interface If a file is not .json ignore it If a file is empty, ignore it

func ResetHjiackStdPipeline

func ResetHjiackStdPipeline()

func SetHijackStdPipeline

func SetHijackStdPipeline(filepath string, stdout, stderr bool)

SetHijackStdPipeline hijacks stdout and stderr outputs into the file path

func WriteFileSafety

func WriteFileSafety(filename string, data []byte, perm os.FileMode) (err error)

WriteFileSafety trys to over write a file safety.

Types

type Ticker

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

Ticker is a thread-safe reusable ticker

func NewTicker

func NewTicker(callback func()) *Ticker

func (*Ticker) Close

func (t *Ticker) Close()

Close closes the ticker.

func (*Ticker) Start

func (t *Ticker) Start(interval time.Duration)

Start starts a ticker running if it is not started

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop stops the ticker.

type Timer

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

func NewTimer

func NewTimer(d time.Duration, callback func()) *Timer

func (*Timer) Stop

func (t *Timer) Stop()

Stop stops the timer.

Jump to

Keyboard shortcuts

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