util

package
v0.0.0-...-22a2038 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayFallback

func ArrayFallback[T any](array []T, fallback []T) []T

ArrayFallback returns the first array if it is not empty, otherwise the second array.

func CollectFnErr

func CollectFnErr[T any](errContainer *MultiError, fn func() (T, error), rightFn func(T))

CollectFnErr collects error from fn function, then execute rightFn function when the fn returns nil error.

func Elvis

func Elvis[T any](condition bool, leftValue T, rightValue T) T

Elvis is a Groovy-like elvis expression.

func IsJobComplete

func IsJobComplete(job batchv1.Job) bool

func IsJobFailed

func IsJobFailed(job batchv1.Job) bool

func IsPodReady

func IsPodReady(pod corev1.Pod) bool

func K8sObjKeyStr

func K8sObjKeyStr(key types.NamespacedName) string

func MapEqual

func MapEqual[K comparable, V comparable](m1, m2 map[K]V) bool

MapEqual checks if two maps are equal.

func MapFallback

func MapFallback[K comparable, V any](mapValue map[K]V, fallback map[K]V) map[K]V

func MapSortedKeys

func MapSortedKeys[K string | int, V any](data map[K]V) []K

MapSortedKeys returns all sorted keys of a map.

func Md5Hash

func Md5Hash(obj any) (string, error)

Md5Hash returns the md5 hash of the given object base on json marshal.

func Md5HashOr

func Md5HashOr(obj any, fallback string) string

Md5HashOr returns the md5 hash of the given object base on json marshal. when error occurs, return the fallback string.

func MergeMaps

func MergeMaps[K comparable, V any](m1, m2 map[K]V) map[K]V

MergeMaps merges two maps into one, when there is a key conflict, prioritize using the value of m2.

func NewConfigMapItemsVolumeSource

func NewConfigMapItemsVolumeSource(configMapName string, items map[string]string) corev1.VolumeSource

func NewConfigMapVolumeSource

func NewConfigMapVolumeSource(configMapName string) corev1.VolumeSource

func NewEmptyDirVolumeSource

func NewEmptyDirVolumeSource() corev1.VolumeSource

func NewEnvVarSecretSource

func NewEnvVarSecretSource(secretName string, key string) *corev1.EnvVarSource

func NewExecLifecycleHandler

func NewExecLifecycleHandler(command ...string) *corev1.LifecycleHandler

func NewHostPathVolumeSource

func NewHostPathVolumeSource(path string) corev1.VolumeSource

func NewHttpGetProbeHandler

func NewHttpGetProbeHandler(path string, httpPort int32) corev1.ProbeHandler

func NewReadWriteOncePVC

func NewReadWriteOncePVC(name string, storageClassName *string, storageRequest *resource.Quantity) corev1.PersistentVolumeClaim

func NewResourceAvgUtilizationMetricSpec

func NewResourceAvgUtilizationMetricSpec(name corev1.ResourceName, avgUnit *int32) acv2.MetricSpec

func NewTcpSocketProbeHandler

func NewTcpSocketProbeHandler(tcpPort int32) corev1.ProbeHandler

func ParallelRun

func ParallelRun[T any](fns ...func() T) []T

ParallelRun executes the functions in parallel and wait for all functions to complete.

func PointerDeRefer

func PointerDeRefer[T any](pointer *T, defaultValue T) T

func PointerFallback

func PointerFallback[T any](pointer *T, fallback *T) *T

PointerFallback returns the first pointer if it is not nil, otherwise the second pointer.

func PointerFallbackAndDeRefer

func PointerFallbackAndDeRefer[T any](pointer *T, fallback *T, defaultValue T) T

PointerFallbackAndDeRefer returns the first pointer if it is not nil, otherwise the second pointer, then dereference the pointer fallback with the defaultValue.

func StringFallback

func StringFallback(str string, fallback string) string

StringFallback returns the first string if it is not empty, otherwise the second string.

Types

type MultiError

type MultiError struct {
	Errors []error
}

MultiError is a list of errors.

func AppendErrMsg

func AppendErrMsg(err error, message string) *MultiError

func MergeErrors

func MergeErrors(errs ...error) *MultiError

MergeErrors merges multiple errors into one.

func (*MultiError) Collect

func (e *MultiError) Collect(err error) bool

func (*MultiError) Dry

func (e *MultiError) Dry() error

Dry returns nil if there is no error in the container.

func (*MultiError) Error

func (e *MultiError) Error() string

type MultiTaggedError

type MultiTaggedError struct {
	Errors map[string]error
}

MultiTaggedError is a list of errors with tags.

func MergeErrorsWithTag

func MergeErrorsWithTag(errors map[string]error) *MultiTaggedError

MergeErrorsWithTag merges multiple errors into one with tags.

func (*MultiTaggedError) Error

func (e *MultiTaggedError) Error() string

Jump to

Keyboard shortcuts

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