utils

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackendObjectReferenceToKey

func BackendObjectReferenceToKey(backendRef gatewayv1.BackendObjectReference) string

BackendObjectReferenceToKey converts a BackendObjectReferenceToKey to a unique string key. It handles nil pointers by using a consistent placeholder.

func ClearMap

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

Generic function to clear a map in place

func ComparePointers

func ComparePointers[T cmp.Ordered](a, b *T) int

ComparePointers compares two pointers to any ordered type. It establishes a consistent sort order where nil values come before non-nil values.

It returns:

  • -1 if a < b
  • 0 if a == b (or both are nil)
  • +1 if a > b

func KeyToBackendObjectReference

func KeyToBackendObjectReference(key string) (gatewayv1.BackendObjectReference, error)

KeyToBackendObjectReference converts a string key back to a gatewayv1.BackendObjectReference. It is the inverse of BackendObjectReferenceToKey.

func KeyToParentRef

func KeyToParentRef(key string) (gatewayv1.ParentReference, error)

KeyToParentRef converts a string key back to a gatewayv1.ParentReference. It is the inverse of ParentRefToKey.

func Keys

func Keys[K comparable, V any](src map[K]V) map[K]struct{}

func MapToSortedListByCreationTimestamp

func MapToSortedListByCreationTimestamp[T ObjectWithTimestamp](objects map[types.NamespacedName]T) []T

func NamespaceAsString

func NamespaceAsString(ns *gatewayv1.Namespace) string

func ObjectKeyFromNamespacedName

func ObjectKeyFromNamespacedName(s string) (client.ObjectKey, error)

func ParentRefToKey

func ParentRefToKey(parentRef gatewayv1.ParentReference) string

ParentRefToKey converts a ParentReference to a unique string key. It handles nil pointers by using a consistent placeholder.

func ParseNamespacedName

func ParseNamespacedName(s string) (types.NamespacedName, error)

ParseNamespacedName parses a "namespace/name" string into a NamespacedName.

func Ptr

func Ptr[V any](v V) *V

Ptr return pointer to a given value

func PtrInt64

func PtrInt64(value int64) *int64

func RouteGroupKindsToString

func RouteGroupKindsToString(routesGK []gatewayv1.RouteGroupKind) string

func SetDifference

func SetDifference[K comparable, V any](mapA, mapB map[K]V) map[K]struct{}

SetDifference finds the keys that are in mapA but not in mapB. It works for any map with a comparable key type K and any value type V.

func SetIntersection

func SetIntersection[K comparable, V any](mapA, mapB map[K]V) map[K]struct{}

func SortByCreationTimestamp

func SortByCreationTimestamp[T ObjectWithTimestamp](objects []T)

func StrPtrToString

func StrPtrToString[T stringer](p *T) string

func StringToPtr

func StringToPtr[T stringer](s string) *T

StringToPtr converts a string to a pointer of a string-based type. If the string is the placeholder "_", it returns nil.

Types

type Errors

type Errors []error

func (*Errors) Add

func (e *Errors) Add(errs ...error)

func (*Errors) AddErrors

func (e *Errors) AddErrors(errs Errors)

func (*Errors) Result

func (e *Errors) Result() error

type ExtractGVK

type ExtractGVK func(object client.Object) schema.GroupVersionKind

ExtractGVK is a function that extracts the GroupVersionKind (GVK) of a client.object. It will log an error if the GKV cannot be extracted.

func NewExtractGKV

func NewExtractGKV(scheme *runtime.Scheme, logger *slog.Logger) ExtractGVK

NewExtractGKV creates a new MustExtractGVK function using the scheme.

type KeyMap

type KeyMap[KEY any, VALUE any] struct {
	// contains filtered or unexported fields
}

func NewKeyMap

func NewKeyMap[KEY any, VALUE any](keygen func(KEY) string) KeyMap[KEY, VALUE]

func (*KeyMap[KEY, VALUE]) Clear

func (m *KeyMap[KEY, VALUE]) Clear()

func (*KeyMap[KEY, VALUE]) DeepCopy

func (m *KeyMap[KEY, VALUE]) DeepCopy() KeyMap[KEY, VALUE]

DeepCopy creates a deep copy of the KeyMap. It requires the VALUE type to have a DeepCopy() method.

func (*KeyMap[KEY, VALUE]) Delete

func (m *KeyMap[KEY, VALUE]) Delete(key KEY)

func (*KeyMap[KEY, VALUE]) Exists

func (m *KeyMap[KEY, VALUE]) Exists(key KEY) bool

func (*KeyMap[KEY, VALUE]) Get

func (m *KeyMap[KEY, VALUE]) Get(key KEY) (VALUE, bool)

func (*KeyMap[KEY, VALUE]) Iterate

func (m *KeyMap[KEY, VALUE]) Iterate(callback func(string, VALUE) bool)

func (*KeyMap[KEY, VALUE]) Len

func (m *KeyMap[KEY, VALUE]) Len() int

func (*KeyMap[KEY, VALUE]) Set

func (m *KeyMap[KEY, VALUE]) Set(key KEY, value VALUE)

type ObjectWithTimestamp

type ObjectWithTimestamp interface {
	GetCreationTimestamp() metav1.Time
	GetName() string
}

Jump to

Keyboard shortcuts

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