common

package
v0.0.0-...-732dc05 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDirNotExists = errors.New("directory doesn't exist")

Functions

func Any

func Any(flags ...bool) bool

func AnyToStruct

func AnyToStruct[T any](data any) (*T, error)

AnyToStruct converts map or struct to selected struct.

func CmpFloat

func CmpFloat(x, y any) int

func CmpInt

func CmpInt(x, y any) int

func CmpNil

func CmpNil(x, y any) int

func CmpString

func CmpString(x, y any) int

func CmpTime

func CmpTime(x, y any) int

func CmpUUID

func CmpUUID(x, y any) int

func ConvertToFloat

func ConvertToFloat(value any, targetType reflect.Type) (any, error)

func ConvertToInt

func ConvertToInt(value any, targetType reflect.Type) (any, error)

func ConvertToString

func ConvertToString(value any, targetType reflect.Type) (any, error)

func ConvertToTime

func ConvertToTime(value any, targetType reflect.Type) (any, error)

func ConvertToUUID

func ConvertToUUID(value any, targetType reflect.Type) (any, error)

func CtxClosed

func CtxClosed(ctx context.Context) bool

func Filter

func Filter[T any](arr []T, f func(T) bool) []T

func GetIndicesInOrder

func GetIndicesInOrder[T comparable](original []T, ordered []T) []int

GetIndicesInOrder returns an array of indexes of the elements from the "original" in the order of the elements from the "ordered".

func GetKey

func GetKey(prefix, name string) string

GetKey function returns unique string key separated by point.

func MakeSet

func MakeSet[T comparable, V any](m1 map[T]V) map[T]struct{}

MakeSet creates new set as map without values.

func NewIncorrectErrIndexError

func NewIncorrectErrIndexError() error

func ShiftElementsToEnd

func ShiftElementsToEnd[T any, K comparable](source []T, orderedShiftedIDs []K, getElemID func(T) K) []T

ShiftElementsToEnd moves all items with ids equal to orderedShiftedIds to the end in the same order. if T is a reference type (struct pointer, interface, ...), then the final slice will contain the original objects.

func SortSlice

func SortSlice(slice []any, comparator CmpFunc)

SortSlice sorts slice of any, where slice elements can be nil, int, float64, string or time.Time.

func Trim

func Trim(str, prefix, suffix string) string

Trim returns part of string between prefix and suffix.

func WalkWithFilter

func WalkWithFilter(dir string, filterFunc func(entry os.DirEntry) bool) ([]string, error)

Types

type CmpFunc

type CmpFunc func(x, y any) int

type ContextCancelError

type ContextCancelError struct{}

func (*ContextCancelError) Error

func (e *ContextCancelError) Error() string

type IncorrectErrIndexError

type IncorrectErrIndexError struct{}

func (*IncorrectErrIndexError) Error

func (e *IncorrectErrIndexError) Error() string

type Job

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

type Syncer

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

func NewSyncer

func NewSyncer() *Syncer

NewSyncer creates a new Syncer.

func (*Syncer) WorkerSyncer

func (s *Syncer) WorkerSyncer() *WorkerSyncer

type WorkerPool

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

WorkerPool represents a pool of goroutines that can execute any function with arguments.

func NewWorkerPool

func NewWorkerPool(fn any, errIdx, workerCount int) *WorkerPool

NewWorkerPool creates a new WorkerPool with the specified number of workers.

func (*WorkerPool) Add

func (wp *WorkerPool) Add(delta int32)

func (*WorkerPool) Done

func (wp *WorkerPool) Done()

func (*WorkerPool) Start

func (wp *WorkerPool) Start()

Start initializes the worker pool and starts processing jobs.

func (*WorkerPool) Stop

func (wp *WorkerPool) Stop()

Stop waits for all workers to finish and closes the Job channel.

func (*WorkerPool) Submit

func (wp *WorkerPool) Submit(args ...any)

Submit adds a new Job to the pool.

func (*WorkerPool) WaitOrError

func (wp *WorkerPool) WaitOrError() error

WaitOrError waits for all workers or first error.

type WorkerSyncer

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

func (*WorkerSyncer) Done

func (s *WorkerSyncer) Done(ctx context.Context)

func (*WorkerSyncer) WaitPrevious

func (s *WorkerSyncer) WaitPrevious(ctx context.Context)

Jump to

Keyboard shortcuts

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