utils

package
v1.14.4 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Copyright (C) 2025, Lux Industries Inc. All rights reserved. See the file LICENSE for licensing terms.

Copyright (C) 2025, Lux Industries Inc. All rights reserved. See the file LICENSE for licensing terms.

Copyright (C) 2025, Lux Industries Inc. All rights reserved. See the file LICENSE for licensing terms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendSlices

func AppendSlices[T any](slices ...[]T) []T

AppendSlices appends multiple slices into a single slice.

func Belongs

func Belongs[T comparable](input []T, elem T) bool

func DirExists

func DirExists(dirName string) bool

DirExists checks if a directory exists.

func ExpandHome

func ExpandHome(path string) string

ExpandHome expands ~ symbol to home directory

func FileExists

func FileExists(filename string) bool

FileExists checks if a file exists.

func GetAPIContext

func GetAPIContext() (context.Context, context.CancelFunc)

Context for API requests

func GetAPILargeContext

func GetAPILargeContext() (context.Context, context.CancelFunc)

Context for API requests with large timeout

func GetTimedContext

func GetTimedContext(timeout time.Duration) (context.Context, context.CancelFunc)

Timed Context

func Map

func Map[T, U any](input []T, f func(T) U) []U

func Retry

func Retry[T any](
	fn func() (T, error),
	maxAttempts int,
	retryInterval time.Duration,
) (T, error)

Retry retries the given function until it succeeds or the maximum number of attempts is reached.

func RetryWithContextGen

func RetryWithContextGen[T any](
	ctxGen func() (context.Context, context.CancelFunc),
	fn func(context.Context) (T, error),
	maxAttempts int,
	retryInterval time.Duration,
) (T, error)

RetryWithContext retries the given function until it succeeds or the maximum number of attempts is reached. For each retry, it generates a fresh context to be used on the call

func Uint32Sort

func Uint32Sort(arr []uint32)

func Unique

func Unique[T comparable](arr []T) []T

Unique returns a new slice containing only the unique elements from the input slice.

func WrapContext

func WrapContext[T any](
	f func() (T, error),
) func(context.Context) (T, error)

WrapContext adds a context based timeout to a given function

Types

This section is empty.

Jump to

Keyboard shortcuts

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