helper

package
v0.1.911 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: Apache-2.0 Imports: 15 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AvgVec32 added in v0.1.775

func AvgVec32(xs ...[]float32) ([]float32, bool)

AvgVec32 averages a variadic set of float32 vectors. Nil or zero-length vectors are ignored. If all are empty/nil, or any non-empty vectors have differing lengths, it returns []float32{} and true.

func CheckForNil

func CheckForNil(params ...any) error

CheckForNil reports the first nil among params including typed-nil.

func CheckPointerToStruct

func CheckPointerToStruct(v any) error

CheckPointerToStruct checks if the provided value is a pointer to a struct.

func ClientEmail added in v0.1.479

func ClientEmail(ctx context.Context, u contract.Unmarshaler, b []byte) (string, error)

ClientEmail returns the client email from the service account.

func Deref

func Deref(v reflect.Value) reflect.Value

Deref dereferences a pointer value recursively.

func ErrorOrNil added in v0.1.583

func ErrorOrNil(err error) string

ErrorOrNil returns the error message if not nil.

func FromPointers added in v0.1.471

func FromPointers[T any](in []*T) []T

FromPointers returns a slice of values from the given slice of pointers.

func IsCI added in v0.1.289

func IsCI() bool

IsCI returns true if the current execution environment is a CI pipeline.

func IsProd added in v0.1.744

IsProd returns true if the current execution environment is a production environment.

func IsUTC added in v0.1.604

func IsUTC(d time.Time) bool

IsUTC checks if the given date is in UTC format.

func KeyBytes added in v0.1.479

func KeyBytes(ctx context.Context, u contract.Unmarshaler, b []byte) ([]byte, error)

KeyBytes returns the private key as bytes from the service account.

func ParseURL added in v0.1.119

func ParseURL(raw string) *url.URL

ParseURL parses a raw string into a *url.URL. Returns a non-nil empty *url.URL on failure.

func Point added in v0.1.425

func Point[T any](x T) *T

Point returns a pointer to the given value.

func PrettyJSON added in v0.1.297

func PrettyJSON(ctx context.Context, m contract.Marshaler, u contract.Unmarshaler, r io.Reader) ([]byte, error)

PrettyJSON pretty-prints a JSON stream using default indentation.

func RandomCode added in v0.1.424

func RandomCode(length int) string

RandomCode returns a random numeric string of the specified length.

func RangeString added in v0.1.346

func RangeString(low, high int) []string

RangeString returns stringified integers between low and high (inclusive).

func Retry

func Retry(opts RetryOptions, f func() error) error

Retry executes the provided function f at least once, retrying up to MaxRetries times if it fails. If MaxRetries is set to 0, the function will still run once. A delay is applied between retries. Returns nil if f succeeds within the allowed attempts; otherwise, returns the last encountered error.

func RoundToMultiple added in v0.1.812

func RoundToMultiple(x, mult float64) float64

RoundToMultiple rounds x to the nearest multiple of multiple.

func SanitizeFilename added in v0.1.497

func SanitizeFilename(n string) string

SanitizeFilename removes unsafe characters from a filename.

func SplitMime added in v0.1.498

func SplitMime(mimeType string) string

SplitMime returns the primary MIME prefix category from the given type.

func ToPointers added in v0.1.471

func ToPointers[T any](in []T) []*T

ToPointers returns a slice of pointers to the given slice of values.

Types

type IntStrRange added in v0.1.815

type IntStrRange struct {
	Ints []int
	Strs []string
}

IntStrRange represents correlated int and string slices for a numeric range.

func RangePair added in v0.1.815

func RangePair(low, high int) IntStrRange

RangePair returns int and stringified integers between low and high (inclusive).

func (IntStrRange) Len added in v0.1.815

func (r IntStrRange) Len() int

type RetryOptions

type RetryOptions struct {
	MaxRetries uint
	RetryDelay time.Duration
}

Jump to

Keyboard shortcuts

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