MCPcopy Create free account
hub / github.com/cozystack/cozystack / ByNamespacedName

Function ByNamespacedName

pkg/registry/sorting/sort.go:36–47  ·  view source on GitHub ↗

ByNamespacedName sorts a slice of objects by Namespace/Name in alphabetical order. Use this for namespace-scoped resources.

(items []T)

Source from the content-addressed store, hash-verified

34// ByNamespacedName sorts a slice of objects by Namespace/Name in alphabetical order.
35// Use this for namespace-scoped resources.
36func ByNamespacedName[T any, PT interface {
37 *T
38 NamespaceGetter
39}](items []T) {
40 slices.SortFunc(items, func(a, b T) int {
41 pa, pb := PT(&a), PT(&b)
42 if res := strings.Compare(pa.GetNamespace(), pb.GetNamespace()); res != 0 {
43 return res
44 }
45 return strings.Compare(pa.GetName(), pb.GetName())
46 })
47}

Callers

nothing calls this directly

Calls 2

GetNamespaceMethod · 0.65
GetNameMethod · 0.65

Tested by

no test coverage detected