Package for sortable key-value properties, like HTTP headers, with functions to remove duplicates.
…
kp := sortprop.KeyProperties{
sortprop.Property{"3", "third"},
sortprop.Property{"1", "first"},
sortprop.Property{"2", "second"},
}
sort.Sort(kp)
…
…
vp := sortprop.ValueProperties{
sortprop.Property{"3", "cccc"},
sortprop.Property{"1", "aaaa"},
sortprop.Property{"2", "bbbb"},
}
sort.Sort(vp)
…
KeyProperties and ValueProperties are just slices, so use append as usual:
list := sortprop.KeyValues{}
p := sortprop.Property{"key", "value"}
list = append(list, p)
These two functions will remove duplicate keys and values:
func UniqueKeys(kp KeyProperties, keeplast bool) KeyProperties
func UniqueValues(vp ValueProperties, keeplast bool) ValueProperties
They return a new slice with only one of each repeated key or value. If keeplast is false, the first of each duplicate element is kept. If keeplast is true, the last one encountered is kept.