commonUtils

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertArr

func ConvertArr[Tin any, Tout any](in []Tin, convertFunc CovertFunc[Tin, Tout]) (convertedItems []Tout, err error)

Converts all the types in

func DefaultIfEqual

func DefaultIfEqual[T comparable](in T, checkEqualTo T, defaultVal T) T

func ExecTask

func ExecTask(ctx context.Context, tasks Task) error

func ExecTasks

func ExecTasks(ctx context.Context, taskTimeout time.Duration, tasks []Task) error

ExecTasks Runs each task in a separate goroutine To set no task timeout -- set taskTimeout to 0

func Must

func Must(err error)

func MustStr2Float

func MustStr2Float[T Float](str string, bitSize int) T

func MustStr2Int

func MustStr2Int[T Int](str string, base int, bitSize int) T

func Retry

func Retry(
	ctx context.Context,
	retryTimes int,
	waitBeforeRetry time.Duration,
	exec Task,
) (success bool, errs []error)

func Str2Bool

func Str2Bool(str string) (val bool, ok bool)

func Str2Float

func Str2Float[T Float](str string, bitSize int) (T, error)

func Str2Int

func Str2Int[T Int](str string, base int, bitSize int) (T, error)

func Ternar

func Ternar[T any](condition bool, ifTrue T, ifFalse T) T

func UnnilArray

func UnnilArray[T any](in []T) []T

If array is equal to nil -- will return an empty array instead

func UnnilMap

func UnnilMap[K comparable, V any](in map[K]V) map[K]V

If map is equal to nil -- will return an empty map instead

func ValOrDefaultNum

func ValOrDefaultNum[T Num](in T, defaultVal T) T

If in is 0 returns the devaultVal. Else returns in

func ValOrDefaultStr

func ValOrDefaultStr(in string, defaultVal string) string

If in is empty returns the devaultVal. Else returns in

Types

type CovertFunc

type CovertFunc[Tin any, Tout any] func(in Tin) (out Tout, err error)

type Float

type Float interface{ ~float32 | ~float64 }

Number types

type IRange

type IRange[T Num] interface {
	Begin() T
	End() T
}

type IStrConvertable

type IStrConvertable interface {
	String() string
}

type Int

type Int interface{ Signed | Unsigned }

Number types

type Num

type Num interface{ Float | Int }

Number types

type Range

type Range[T Num] struct {
	IRange[T]
	// contains filtered or unexported fields
}

func NewRange

func NewRange[T Num](begin T, end T) *Range[T]

func (Range[T]) Begin

func (r Range[T]) Begin() T

func (Range[T]) End

func (r Range[T]) End() T

type Signed

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

Number types

type Task

type Task func(ctx context.Context) error

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint32 | ~uint64
}

Number types

Jump to

Keyboard shortcuts

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