blob: cbaecdc5aabe9bdd7e071ca7db7a8d213f2405b5 [file] [log] [blame]
/*
* Copyright 2022-present Open Networking Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package format
import "sort"
// Pair structure
type Pair struct {
Key string
Value interface{}
}
// PairList type
type PairList []Pair
func (p PairList) Len() int { return len(p) }
func (p PairList) Less(i, j int) bool { return p[i].Key < p[j].Key }
func (p PairList) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func sortData(data map[string]interface{}) PairList {
pl := make(PairList, len(data))
i := 0
for k, v := range data {
pl[i] = Pair{k, v}
i++
}
sort.Sort(pl)
return pl
}