util

package
v0.0.0-...-12e0a72 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(n int) int

func BoolAddr

func BoolAddr(b bool) *bool

func CopyMap

func CopyMap[K comparable, V any](m map[K]V) map[K]V

func Filter

func Filter[K any](slice []K, keep func(k K) bool) []K

func GetEnv

func GetEnv(key, fallback string) string

func GetEnvBool

func GetEnvBool(key string, fallback bool) bool

func GetEnvOrError

func GetEnvOrError(key string) (string, error)

func GetKeys

func GetKeys[K comparable, V any](maps ...map[K]V) []K

func GetNamespacedName

func GetNamespacedName(object HasNamespacedName) types.NamespacedName

func HashFnv32a

func HashFnv32a(str string) string

func InSlice

func InSlice[K comparable](item K, slice []K) bool

func IterPermutations

func IterPermutations[K any](slice []K, f func(k []K) (bool, error)) error

IterPermutations calls `f` providing as argument each possible permutation `slice`. It stops iterating if `f` returns either `false` or an error, and it returns an error if any call to `f` returns error.

func LocalEndpoint

func LocalEndpoint(path, file string) (string, error)

LocalEndpoint returns the full path to a unix socket at the given endpoint

func Max

func Max[K constraints.Ordered](v1 K, v2 K) K

func Min

func Min[K constraints.Ordered](v1 K, v2 K) K

func RandomStringLowercase

func RandomStringLowercase(n int) string

func ResetTimer

func ResetTimer(timer *time.Timer, duration time.Duration)

ResetTimer stops&drains the provided timer and resets it to the provided duration

func StopTimer

func StopTimer(timer *time.Timer)

StopTimer stops and drains the provided timer

func StringAddr

func StringAddr(s string) *string

func UnorderedEqual

func UnorderedEqual[K any](first []K, second []K) bool

Types

type Batcher

type Batcher[T any] struct {
	// contains filtered or unexported fields
}

func NewBatcher

func NewBatcher[T any](timeoutDuration time.Duration, idleDuration time.Duration) Batcher[T]

func NewBufferedBatcher

func NewBufferedBatcher[T any](timeoutDuration time.Duration, idleDuration time.Duration, bufferSize int) Batcher[T]

func (*Batcher[T]) Add

func (b *Batcher[T]) Add(item T)

func (*Batcher[T]) Ready

func (b *Batcher[T]) Ready() chan []T

func (*Batcher[T]) Reset

func (b *Batcher[T]) Reset()

Reset resets the batcher by resetting the timers and clearing the current batch

func (*Batcher[T]) Start

func (b *Batcher[T]) Start(ctx context.Context) error

type HasNamespacedName

type HasNamespacedName interface {
	GetName() string
	GetNamespace() string
}

type PermutationGenerator

type PermutationGenerator[K any] struct {
	// contains filtered or unexported fields
}

func NewPermutationGenerator

func NewPermutationGenerator[K any](sourceSlice []K) PermutationGenerator[K]

func (*PermutationGenerator[K]) Next

func (p *PermutationGenerator[K]) Next() bool

func (*PermutationGenerator[K]) Permutation

func (p *PermutationGenerator[K]) Permutation() []K

type Set

type Set[K comparable] map[K]empty

func (Set[K]) Add

func (s Set[K]) Add(item K)

func (Set[K]) Items

func (s Set[K]) Items() []K

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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