utils

package
v0.0.0-...-2aa3bab Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ParseUint   = StrParser[uint](strconv.ParseUint, 0, 64)
	ParseUint8  = StrParser[uint8](strconv.ParseUint, 0, 8)
	ParseUint16 = StrParser[uint16](strconv.ParseUint, 0, 16)
	ParseUint32 = StrParser[uint32](strconv.ParseUint, 0, 32)
	ParseUint64 = StrParser[uint64](strconv.ParseUint, 0, 64)
	ParseInt    = StrParser[int](strconv.ParseInt, 0, 64)
	ParseInt8   = StrParser[int8](strconv.ParseInt, 0, 8)
	ParseInt16  = StrParser[int16](strconv.ParseInt, 0, 16)
	ParseInt32  = StrParser[int32](strconv.ParseInt, 0, 32)
	ParseInt64  = StrParser[int64](strconv.ParseInt, 0, 64)
)

Functions

func After

func After[T any, F ft[T]](done <-chan T, f F, cBreaks ...<-chan struct{})

After do when done is closed (unblocked)

func Array

func Array[T any](s ...T) []T

func BackExec

func BackExec(exec func(), onDone ...func()) <-chan struct{}

func BackQueue

func BackQueue(rollback *func(), autoRunIfErr *error) (q funcQueue)

BackQueue 先进后出的回滚函数队列

  • rollback: 这是返回参数,回滚方法。
  • autoRunIfErr: 这是传入参数,在 `defer fq.ErrDefer()` 中判断*error不为空则自动执行回滚

func BackwardRun

func BackwardRun(fs ...func())

func CSelect

func CSelect[T any](cSelect <-chan T, cBreaks ...<-chan struct{}) (v T, ok, breaked bool)

SelectOnce select `cSelect` chan, return it (blocked)

v: if recv from cSelect
ok: if cSelect is not closed
breaked: if recv from cBreaks or any cBreaks is closed...

like:

select{
	 case <- cBreaks[...]:
		v = nil, ok = false, breaked = true
	 case v, ok:= cSelect:
		v = v, ok = ok, breaked = false
}

func CompactUniq

func CompactUniq[Slice ~[]T, T comparable](s Slice, inplace ...bool) Slice

func Conv

func Conv[Slice ~[]T, T any](s Slice, cleanFn func(T) T, inplace ...bool) (result Slice)

func Eol

func Eol[T any](_ T, err error) error

func Eon

func Eon[T any, E any](v T, _ E) T

func First

func First[T any](v []T) T

func FirstOr

func FirstOr[T any](v []T, def ...T) T

func Flat

func Flat[T any](s [][]T) []T

func HasPrefix

func HasPrefix(s, prefix string, ignoreCase ...bool) bool

func HumanBytes

func HumanBytes[T UintT | IntT](n T, prec ...int) string

func Iif

func Iif[T any](c bool, t, f T) T

func LineSeq

func LineSeq(r io.Reader) iter.Seq[string]

func LineWalk

func LineWalk(r io.Reader, f func(s string))

func LineWriter

func LineWriter(lineRead func(line string)) io.WriteCloser

func LogStd

func LogStd(w io.Writer) *log.Logger

func Map

func Map[T, R any](s []T, conv func(T, int) R) []R

func PasswordMask

func PasswordMask(s string) string

func RandText

func RandText(n int) (s string)

RandText 生成一个指定长度的随机字符串。

func Reduce

func Reduce[T, R any](s []T, walk func(agg R, item T, i int) R, init R) R

func ReduceSeq

func ReduceSeq[T, R any](seq iter.Seq[T], walk func(agg R, item T) R, init R) R

func ReduceSeq2

func ReduceSeq2[T, R any](seq iter.Seq2[int, T], walk func(agg R, item T, index int) R, init R) R

func Replace

func Replace[Slice ~[]T, T any](s Slice, replaceFn func(T) (T, error)) (result Slice, err error)

func Run

func Run(fs ...func())

func SelectDo

func SelectDo[T any](cSelect <-chan T, f func(T, bool), cBreaks ...<-chan struct{}) (breaked bool)

SelectDo do if recv from sSelect (blocked)

func Sleep

func Sleep(d time.Duration, cBreaks ...<-chan struct{}) (breaked bool)

Sleep breakable sleep (blocked)

func StrParser

func StrParser[R UintT | IntT, T1, T2 any, R64 uint64 | int64](f func(string, T1, T2) (R64, error), t1 T1, t2 T2) func(string) (R, error)

func String

func String[T IntT | UintT](v T) string

Types

type IntT

type IntT interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type UintT

type UintT interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

Jump to

Keyboard shortcuts

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