Documentation
¶
Overview ¶
Package utils provides utility functions for key mapping and conversions.
Index ¶
- func BackendObjectReferenceToKey(backendRef gatewayv1.BackendObjectReference) string
- func ClearMap[K comparable, V any](m map[K]V)
- func ComparePointers[T cmp.Ordered](a, b *T) int
- func ConvertSliceWithFunc[U, V any](arg []U, f func(U) V) []V
- func ConvertV1Alpha2HostnameToString(hostname v1alpha2.Hostname) string
- func GetHostnamesForRouteWithListener(listenerHostname *string, routeHostnames []string) []string
- func GetNamespacedName(name gatewayv1.ObjectName, namespace *gatewayv1.Namespace, ...) types.NamespacedName
- func KeyToBackendObjectReference(key string) (gatewayv1.BackendObjectReference, error)
- func KeyToParentRef(key string) (gatewayv1.ParentReference, error)
- func Keys[K comparable, V any](src map[K]V) map[K]struct{}
- func MapToSortedListByCreationTimestamp[T ObjectWithTimestamp](objects map[types.NamespacedName]T) []T
- func NamespaceAsString(ns *gatewayv1.Namespace) string
- func ObjectKeyFromNamespacedName(s string) (client.ObjectKey, error)
- func ParentRefToKey(parentRef gatewayv1.ParentReference) string
- func ParseNamespacedName(s string) (types.NamespacedName, error)
- func PointerDefaultValueIfNil[T any](arg *T) T
- func RouteGroupKindsToString(routesGK []gatewayv1.RouteGroupKind) string
- func SetDifference[K comparable, V any](mapA, mapB map[K]V) map[K]struct{}
- func SetIntersection[K comparable, V any](mapA, mapB map[K]V) map[K]struct{}
- func SortByCreationTimestamp[T ObjectWithTimestamp](objects []T)
- func StrPtrToString[T stringer](p *T) string
- func StringToPtr[T stringer](s string) *T
- type DedicatedGateway
- type DedicatedNamespaces
- type Errors
- type KeyMap
- func (m *KeyMap[KEY, VALUE]) Clear()
- func (m *KeyMap[KEY, VALUE]) Delete(key KEY)
- func (m *KeyMap[KEY, VALUE]) Exists(key KEY) bool
- func (m *KeyMap[KEY, VALUE]) Get(key KEY) (VALUE, bool)
- func (m *KeyMap[KEY, VALUE]) Iterate(callback func(string, VALUE) bool)
- func (m *KeyMap[KEY, VALUE]) Len() int
- func (m *KeyMap[KEY, VALUE]) Set(key KEY, value VALUE)
- type ObjectWithTimestamp
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 ¶
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 ConvertSliceWithFunc ¶ added in v0.8.0
func ConvertSliceWithFunc[U, V any](arg []U, f func(U) V) []V
func ConvertV1Alpha2HostnameToString ¶ added in v0.8.0
func GetHostnamesForRouteWithListener ¶ added in v0.8.0
GetHostnamesForRouteWithListener returns the hostnames that match a listener and a route. The rules are based on the Gateway API specification. If the listener hostname is not set, it matches any route hostname. If the listener hostname is a wildcard, it checks if it matches any route hostname. If the route hostnames are empty, the listener hostname matches the route hostnames.
func GetNamespacedName ¶ added in v0.8.0
func GetNamespacedName(name gatewayv1.ObjectName, namespace *gatewayv1.Namespace, defaultNamespace string) types.NamespacedName
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 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 PointerDefaultValueIfNil ¶ added in v0.8.0
func PointerDefaultValueIfNil[T any](arg *T) T
PointerDefaultValueIfNil dereferences a pointer and returns its value. If the pointer is nil, the zero value of T is returned instead.
Example:
x := 42 v := PointerDefaultValueIfNil(&x) // returns 42 v := PointerDefaultValueIfNil(nil) // returns 0 (zero value of int)
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 DedicatedGateway ¶ added in v1.0.3
type DedicatedGateway struct {
// contains filtered or unexported fields
}
func NewDedicatedGateway ¶ added in v1.0.3
func NewDedicatedGateway(nsName types.NamespacedName) DedicatedGateway
func (DedicatedGateway) Check ¶ added in v1.0.3
func (dg DedicatedGateway) Check(gatewayNsName types.NamespacedName) bool
Check reports whether gatewayNsName matches the dedicated Gateway this instance was configured with. If no dedicated Gateway was configured (both name and namespace are empty), it returns true, allowing all gateways through.
type DedicatedNamespaces ¶ added in v1.0.3
type DedicatedNamespaces struct {
// contains filtered or unexported fields
}
func NewDedicatedNamespaces ¶ added in v1.0.3
func NewDedicatedNamespaces(namespaces []string) DedicatedNamespaces
func (DedicatedNamespaces) Check ¶ added in v1.0.3
func (dn DedicatedNamespaces) Check(gatewayNsName types.NamespacedName) bool