-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsorters.go
33 lines (27 loc) · 878 Bytes
/
sorters.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package restfulSorters
import (
"github.com/emicklei/go-restful-swagger12"
"sort"
)
func AscendingByResourcePath(apiDeclarationMap *swagger.ApiDeclarationList) {
// First get the offset and resource path
paths := make([]string, len(apiDeclarationMap.List))
for k, apiDeclaration := range apiDeclarationMap.List {
paths[k] = apiDeclaration.ResourcePath
}
// Next, sort the values
sort.Strings(paths)
// Then, create our new list
newList := make([]swagger.ApiDeclaration, len(apiDeclarationMap.List))
// Iterate over some stuff and populate the new list...
for i, resourcePath := range paths {
for _, apiDeclaration := range apiDeclarationMap.List {
if resourcePath == apiDeclaration.ResourcePath {
newList[i] = apiDeclaration
break
}
}
}
// Finally, override list definition with our newly sorted list.
apiDeclarationMap.List = newList
}