util

package
v0.0.0-...-687f649 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 22 Imported by: 6

Documentation

Index

Constants

View Source
const TimeLayout = time.RFC3339

Variables

This section is empty.

Functions

func And

func And(in ...bool) bool

func BoolSwitch

func BoolSwitch[T interface{}](s bool, t, f T) T

BoolSwitch define bool switch for defined types - in case of true t T is returned, in case of false f T

func CheckConditionalNil

func CheckConditionalNil[T interface{}](in ConditionalFunction[T]) *T

func CheckConditionalP1Nil

func CheckConditionalP1Nil[T, P1 interface{}](in ConditionalP1Function[T, P1], p1 P1) *T

func CompareInt

func CompareInt(a, b int) bool

func CompareInt64

func CompareInt64(a, b int64) bool

func CompareInt64p

func CompareInt64p(a, b *int64) bool

func CompareIntp

func CompareIntp(a, b *int) bool

func CompareJSON

func CompareJSON[T interface{}](a, b T) (bool, error)

func CompareJSONP

func CompareJSONP[T interface{}](a, b *T) (bool, error)

func CopyFullMap

func CopyFullMap[K comparable, V any](src map[K]V) map[K]V

func CopyMap

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

func CreateSignalContext

func CreateSignalContext(ctx context.Context) context.Context

CreateSignalContext creates and returns the context which is closed when one of the provided signal occurs. SIGINT and SIGTERM is used by default.

func Default

func Default[T interface{}]() T

Default returns generic default value for type T

func DefaultInterface

func DefaultInterface[T interface{}]() interface{}

DefaultInterface returns generic default value for type T as Interface

func ExtractLabel

func ExtractLabel(obj meta.Object, label string) (string, bool)

func First

func First[T interface{}](input ...*T) *T

First returns first not nil value

func FirstNotDefault

func FirstNotDefault[T interface{}](input ...T) T

FirstNotDefault returns first not default value

func InitType

func InitType[T interface{}](in *T) *T

InitType initialise object if it is nil pointer

func IterateSorted

func IterateSorted[V any](m map[string]V, cb func(string, V))

func LastFromList

func LastFromList[T interface{}](in []T) T

LastFromList returns last element on the list

func MD5

func MD5(data []byte) string

func MD5FromString

func MD5FromString(data string) string

func MergeMaps

func MergeMaps[K comparable, V any](override bool, maps ...map[K]V) map[K]V

func NewType

func NewType[T interface{}](input T) *T

NewType returns a reference to a simple type with given value.

func NewTypeOrNil

func NewTypeOrNil[T interface{}](input *T) *T

NewTypeOrNil returns nil if input is nil, otherwise returns a clone of the given value.

func NormalizeEnv

func NormalizeEnv(env string) string

NormalizeEnv normalizes environment variables.

func OpenWithRead

func OpenWithRead(path string, size int) ([]byte, error)

func Or

func Or(in ...bool) bool

func ParallelThread

func ParallelThread(max int) (chan struct{}, func())

func ParseAgencyTime

func ParseAgencyTime(s string) (time.Time, bool)

func ParseTime

func ParseTime(s string, layouts ...string) (time.Time, int)

func Rand

func Rand() *rand.Rand

func RandomElement

func RandomElement[T interface{}](in []T) (T, bool)

func Read

func Read(in io.Reader, buff []byte) (int, error)

func RunParallel

func RunParallel(max int, actions ...func() error) error

RunParallel runs actions parallelly throttling them to the given maximum number.

func SHA256

func SHA256(data []byte) string

func SHA256FromJSON

func SHA256FromJSON[T interface{}](a T) (string, error)

func SHA256FromString

func SHA256FromString(data string) string

func SortKeys

func SortKeys(m interface{}) []string

func TimeAgencyLayouts

func TimeAgencyLayouts() []string

func TimeCompareEqual

func TimeCompareEqual(a, b meta.Time) bool

TimeCompareEqual compares two times, allowing an error of 1s

func TimeCompareEqualPointer

func TimeCompareEqualPointer(a, b *meta.Time) bool

TimeCompareEqualPointer compares two times, allowing an error of 1s Returns true if both pointers are nil

func TypeOrDefault

func TypeOrDefault[T interface{}](input *T, defaultValue ...T) T

TypeOrDefault returns the default value (or T default value) if input is nil, otherwise returns the referenced value.

func WithContextTimeoutP1A1

func WithContextTimeoutP1A1[P1, A1 interface{}](ctx context.Context, timeout time.Duration, f func(context.Context, A1) P1, a1 A1) P1

func WithContextTimeoutP1A2

func WithContextTimeoutP1A2[P1, A1, A2 interface{}](ctx context.Context, timeout time.Duration, f func(context.Context, A1, A2) P1, a1 A1, a2 A2) P1

func WithContextTimeoutP1A4

func WithContextTimeoutP1A4[P1, A1, A2, A3, A4 interface{}](ctx context.Context, timeout time.Duration, f func(context.Context, A1, A2, A3, A4) P1, a1 A1, a2 A2, a3 A3, a4 A4) P1

func WithContextTimeoutP2A2

func WithContextTimeoutP2A2[P1, P2, A1, A2 interface{}](ctx context.Context, timeout time.Duration, f func(context.Context, A1, A2) (P1, P2), a1 A1, a2 A2) (P1, P2)

func WithContextTimeoutP2A4

func WithContextTimeoutP2A4[P1, P2, A1, A2, A3, A4 interface{}](ctx context.Context, timeout time.Duration, f func(context.Context, A1, A2, A3, A4) (P1, P2), a1 A1, a2 A2, a3 A3, a4 A4) (P1, P2)

func WithContextTimeoutP4A3

func WithContextTimeoutP4A3[P1, P2, P3, P4, A1, A2, A3 interface{}](ctx context.Context, timeout time.Duration, f func(context.Context, A1, A2, A3) (P1, P2, P3, P4), a1 A1, a2 A2, a3 A3) (P1, P2, P3, P4)

func WithDefault

func WithDefault[T interface{}](in *T) T

WithDefault returns generic default value for type T if in is nil

func WithKubernetesContextTimeoutP1A1

func WithKubernetesContextTimeoutP1A1[P1, A1 interface{}](ctx context.Context, f func(context.Context, A1) P1, a1 A1) P1

func WithKubernetesContextTimeoutP1A2

func WithKubernetesContextTimeoutP1A2[P1, A1, A2 interface{}](ctx context.Context, f func(context.Context, A1, A2) P1, a1 A1, a2 A2) P1

func WithKubernetesContextTimeoutP1A4

func WithKubernetesContextTimeoutP1A4[P1, A1, A2, A3, A4 interface{}](ctx context.Context, f func(context.Context, A1, A2, A3, A4) P1, a1 A1, a2 A2, a3 A3, a4 A4) P1

func WithKubernetesContextTimeoutP2A2

func WithKubernetesContextTimeoutP2A2[P1, P2, A1, A2 interface{}](ctx context.Context, f func(context.Context, A1, A2) (P1, P2), a1 A1, a2 A2) (P1, P2)

func WithKubernetesContextTimeoutP2A4

func WithKubernetesContextTimeoutP2A4[P1, P2, A1, A2, A3, A4 interface{}](ctx context.Context, f func(context.Context, A1, A2, A3, A4) (P1, P2), a1 A1, a2 A2, a3 A3, a4 A4) (P1, P2)

func WithKubernetesContextTimeoutP4A3

func WithKubernetesContextTimeoutP4A3[P1, P2, P3, P4, A1, A2, A3 interface{}](ctx context.Context, f func(context.Context, A1, A2, A3) (P1, P2, P3, P4), a1 A1, a2 A2, a3 A3) (P1, P2, P3, P4)

func WithKubernetesPatch

func WithKubernetesPatch[P1 meta.Object](ctx context.Context, obj string, client PatchInterface[P1], p ...patch.Item) (P1, error)

func WriteAll

func WriteAll(out io.Writer, data []byte) (int, error)

Types

type ConditionalFunction

type ConditionalFunction[T interface{}] func() (T, bool)

type ConditionalP1Function

type ConditionalP1Function[T, P1 interface{}] func(p1 P1) (T, bool)

type EnvironmentVariable

type EnvironmentVariable string

EnvironmentVariable is a wrapper to get environment variables

func (EnvironmentVariable) Exists

func (e EnvironmentVariable) Exists() bool

Exists check if variable is defined

func (EnvironmentVariable) Get

func (e EnvironmentVariable) Get() string

Get fetch variable. If variable does not exist empty string is returned

func (EnvironmentVariable) GetOrDefault

func (e EnvironmentVariable) GetOrDefault(d string) string

GetOrDefault fetch variable. If variable is not defined default value is returned

func (EnvironmentVariable) Lookup

func (e EnvironmentVariable) Lookup() (string, bool)

Lookup for environment variable

func (EnvironmentVariable) String

func (e EnvironmentVariable) String() string

String return string representation of environment variable name

type Interval

type Interval time.Duration

Interval is a specialization of Duration so we can add some helper functions to that.

func (Interval) After

func (i Interval) After() <-chan time.Time

After waits for the interval to elapse and then sends the current time on the returned channel.

func (Interval) Backoff

func (i Interval) Backoff(factor float64, maxInt Interval) Interval

Backoff returns an interval that is equal to min(i*factor, maxInt).

func (Interval) IncreaseTo

func (i Interval) IncreaseTo(x Interval) Interval

IncreaseTo returns an interval that is equal to max(x, i).

func (Interval) ReduceTo

func (i Interval) ReduceTo(x Interval) Interval

ReduceTo returns an interval that is equal to min(x, i).

func (Interval) String

func (i Interval) String() string

type List

type List[T any] []T

func MapList

func MapList[T, V comparable](in List[T], fn func(T) V) List[V]

func (List[T]) Append

func (l List[T]) Append(items ...T) List[T]

func (List[T]) Count

func (l List[T]) Count(fn func(T) bool) int

func (List[T]) Filter

func (l List[T]) Filter(fn func(T) bool) List[T]

func (List[T]) List

func (l List[T]) List() []T

func (List[T]) Sort

func (l List[T]) Sort(fn func(T, T) bool) List[T]

type Loader

type Loader[T any] interface {
	MustGet() T

	Get() (T, error)
}

func NewLoader

func NewLoader[T any](gen LoaderGen[T]) Loader[T]

func NewYamlLoader

func NewYamlLoader[T any](data []byte) Loader[T]

type LoaderGen

type LoaderGen[T any] func() (T, error)

type PatchInterface

type PatchInterface[P1 meta.Object] interface {
	Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (P1, error)
}

Jump to

Keyboard shortcuts

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