util

package module
v0.0.0-...-0823ec5 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2023 License: MIT Imports: 20 Imported by: 2

README

util

常用工具库

Documentation

Index

Constants

View Source
const (
	Highlight                 = 1
	FrontGreen                = 32
	BackBlack                 = 40
	BasicCompletedIcon   rune = '█'
	BasicUnCompletedIcon byte = ' '
)

Variables

This section is empty.

Functions

func AllDone

func AllDone(ctx context.Context, fs ...func())

func AnyDone

func AnyDone(ctx context.Context, fs ...func() (res interface{}, needReturn bool)) (res interface{}, withNeedReturn bool)

并发执行fs中的所有函数, 且在fs中某个函数最先返回(res0, true)时返回(res0, true), 如果fs中所有函数均返回(res, false), 则在fs中所有函数执行完之后返回(nil, false)

func Async

func Async(ctx context.Context, task func()) <-chan struct{}

func CycleRun

func CycleRun(f func(), handleFPanic func(interface{}), timeInterval time.Duration, maxRunTimes *uint64) (cancel func())

 以周期timeInterval执行函数f, 调用cancel()可以停止周期执行任务, 多次调用cancel会panic

func ExternalIP

func ExternalIP() (net.IP, error)

func Retry

func Retry(f func(sn int) (end bool), times int, maxSleepTime time.Duration)

RetryDo Retry sn表示这是第几次执行f, 至多执行times次f

func Stringer

func Stringer(obj interface{}) fmt.Stringer

示例用法: logs.CtxDebug(ctx, "%v", xf.Stringer(obj))或logs.CtxDebug(ctx, "%s", xf.Stringer(obj))

func TernaryInt

func TernaryInt(condi bool, ifTrue int, ifFalse int) int

func TernaryInt16

func TernaryInt16(condi bool, ifTrue int16, ifFalse int16) int16

func TernaryInt16Slice

func TernaryInt16Slice(condi bool, ifTrue []int16, ifFalse []int16) []int16

func TernaryInt32

func TernaryInt32(condi bool, ifTrue int32, ifFalse int32) int32

func TernaryInt32Slice

func TernaryInt32Slice(condi bool, ifTrue []int32, ifFalse []int32) []int32

func TernaryInt64

func TernaryInt64(condi bool, ifTrue int64, ifFalse int64) int64

func TernaryInt64Slice

func TernaryInt64Slice(condi bool, ifTrue []int64, ifFalse []int64) []int64

func TernaryInt8

func TernaryInt8(condi bool, ifTrue int8, ifFalse int8) int8

func TernaryInt8Slice

func TernaryInt8Slice(condi bool, ifTrue []int8, ifFalse []int8) []int8

func TernaryIntSlice

func TernaryIntSlice(condi bool, ifTrue []int, ifFalse []int) []int

func TernaryString

func TernaryString(condi bool, ifTrue string, ifFalse string) string

func TernaryUint

func TernaryUint(condi bool, ifTrue uint, ifFalse uint) uint

func TernaryUint16

func TernaryUint16(condi bool, ifTrue uint16, ifFalse uint16) uint16

func TernaryUint16Slice

func TernaryUint16Slice(condi bool, ifTrue []uint16, ifFalse []uint16) []uint16

func TernaryUint8

func TernaryUint8(condi bool, ifTrue uint8, ifFalse uint8) uint8

func TernaryUint8Slice

func TernaryUint8Slice(condi bool, ifTrue []uint8, ifFalse []uint8) []uint8

func TernaryUintSlice

func TernaryUintSlice(condi bool, ifTrue []uint, ifFalse []uint) []uint

func Traverse

func Traverse(root Node, multiRoutine bool)

func TrimWhite

func TrimWhite(s string) string

Types

type Bar

type Bar interface {
	// 更新成功时返回true
	Update(cur uint64) bool
}

func NewBar

func NewBar(total uint64) Bar

NewBarWithConfig 通过自定义配置对象创建进度条对象

type BatchOutput

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

func NewBatchOutput

func NewBatchOutput(batchSize uint64, flushTimeInterval time.Duration) *BatchOutput

BatchOutput用于将输入元素聚合后输出, 主要参数为BatchSize和FlushTimeInterval, 含义如下:

BatchSize: 聚合的batch大小
FlushTimeInterval: 超过FlushTimeInterval时间内输入元素的个数未达到BatchSize时, 将当前剩余所有元素强制聚合后输出

func (*BatchOutput) ChangeBatchSizeOrFlushTimeInterval

func (b *BatchOutput) ChangeBatchSizeOrFlushTimeInterval(newBatchSize *uint64, newFlushTimeInterval *time.Duration) error

func (*BatchOutput) GetBatchElements

func (b *BatchOutput) GetBatchElements(withBlock bool) ([]interface{}, error)

func (*BatchOutput) GetStatus

func (b *BatchOutput) GetStatus() (BatchOutputStatus, error)

func (*BatchOutput) PushElement

func (b *BatchOutput) PushElement(x interface{}) error

func (*BatchOutput) Stop

func (b *BatchOutput) Stop()

type BatchOutputStatus

type BatchOutputStatus struct {
	BatchSize         uint64
	FlushTimeInterval time.Duration
}

type Node

type Node interface {
	Id() string       // 结点唯一标识
	Task()            // 结点执行的函数
	Children() []Node // 所有的子结点
}

Jump to

Keyboard shortcuts

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