util

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs added in v0.6.0

func Abs[N Number](n N) N

func BoolToStr

func BoolToStr(b bool, ifTrue string, ifFalse string) string

func Clone added in v0.6.0

func Clone[T any](t *T) *T

func DeepEqualWithUnionHandling added in v0.9.0

func DeepEqualWithUnionHandling(v1, v2 reflect.Value) bool

func DefaultBoolIfNil

func DefaultBoolIfNil(b *bool, defaultB bool) bool

func DefaultIfError

func DefaultIfError(fn StringerWithError, defaultS string) string

func DefaultIfNil

func DefaultIfNil(s *string, defaultS string) string

func DefaultIfNotInMap added in v0.2.0

func DefaultIfNotInMap(m map[string]string, key string, def string) string

func DefaultString

func DefaultString(s string, defaultS string) string

func EnsureMap added in v0.4.0

func EnsureMap[T comparable, U any](m map[T]U) map[T]U

EnsureMap takes a map as input and guarantees that it is not nil. If the input map is nil, it initializes and returns a new empty map of the same type. If the input map is already initialized, it simply returns the map unchanged.

func GetFromMap added in v0.4.0

func GetFromMap[K comparable, V any](in map[K]V, key K) (V, bool)

func GetOrgIdFromContext added in v0.9.0

func GetOrgIdFromContext(ctx context.Context) (uuid.UUID, bool)

func GetResourceOwner

func GetResourceOwner(owner *string) (string, string, error)

func IsEmptyString

func IsEmptyString(s *string) bool

func LabelArrayToMap

func LabelArrayToMap(labels []string) map[string]string

func LabelMapToArray

func LabelMapToArray(labels *map[string]string) []string

func LabelsMatchLabelSelector

func LabelsMatchLabelSelector(labels map[string]string, labelSelector map[string]string) bool

func Max added in v0.4.0

func Max[N Number](n1, n2 N) N

func MergeLabels

func MergeLabels(labels ...map[string]string) map[string]string

func Min added in v0.4.0

func Min[N Number](n1, n2 N) N

func Must

func Must(err error)

func MustString

func MustString(fn StringerWithError) string

func OwnerQueryParamsToArray

func OwnerQueryParamsToArray(ownerQueryParam *string) []string

func ResourceOwner added in v0.4.0

func ResourceOwner(kind string, name string) string

func SetResourceOwner

func SetResourceOwner(kind string, name string) *string

func SingleQuote

func SingleQuote(input []string) []string

func SliceToPtrWithNilDefault

func SliceToPtrWithNilDefault(s []string) *[]string

func StringsAreEqual added in v0.7.0

func StringsAreEqual(a, b *string) bool

func StructToMap added in v0.6.0

func StructToMap(obj interface{}) (map[string]interface{}, error)

func TimeStampString added in v0.4.0

func TimeStampString() string

func TimeStampStringPtr

func TimeStampStringPtr() *string

func ToPtrWithNilDefault added in v0.4.0

func ToPtrWithNilDefault[T comparable](i T) *T

func WithOrganizationID added in v0.9.0

func WithOrganizationID(ctx context.Context, orgID uuid.UUID) context.Context

Types

type Duration

type Duration time.Duration

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (Duration) String

func (d Duration) String() string

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

type Number added in v0.4.0

type Number interface {
	constraints.Integer | constraints.Float
}

type Singleton added in v0.6.0

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

func (*Singleton[T]) GetOrInit added in v0.6.0

func (s *Singleton[T]) GetOrInit(t *T) *T

func (*Singleton[T]) Instance added in v0.6.0

func (s *Singleton[T]) Instance() *T

type StringerWithError

type StringerWithError func() (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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