emissary/internal/agent/metadata/sort.go

38 lines
565 B
Go
Raw Permalink Normal View History

package metadata
import (
"sort"
)
type Tuple struct {
Key string `json:"key"`
Value any `json:"value"`
}
func Sort(metadata map[string]any) []Tuple {
keys := make([]string, 0, len(metadata))
for k := range metadata {
keys = append(keys, k)
}
sort.Strings(keys)
tuples := make([]Tuple, len(keys))
for i, k := range keys {
tuples[i] = Tuple{k, metadata[k]}
}
return tuples
}
func FromSorted(tuples []Tuple) map[string]any {
metadata := make(map[string]any)
for _, t := range tuples {
metadata[t.Key] = t.Value
}
return metadata
}