Skip to content

Commit

Permalink
simpler functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zerolethanh committed Nov 15, 2022
1 parent 28e4711 commit 47114ba
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func printByPathStacks(stacks []*fiber.Route) {
byPathStacks := lo.GroupBy(stacks, func(stack *fiber.Route) string {
return stack.Path
})
paths, sortedByPathStacks := sortMapByKey(byPathStacks)
paths := sortedKeys(byPathStacks)

for _, path := range paths {
color.HiYellow(path)
routes := sortedByPathStacks[path]
routes := byPathStacks[path]
fmt.Print(" ➜")
for _, route := range routes {
params := getRouteParams(route)
Expand Down Expand Up @@ -90,17 +90,8 @@ func getRouteParams(route *fiber.Route) string {
return params
}

func sortMapByKey(m map[string][]*fiber.Route) ([]string, map[string][]*fiber.Route) {
var keys []string
for k := range m {
keys = append(keys, k)
}
func sortedKeys(m map[string][]*fiber.Route) []string {
keys := lo.Keys(m)
sort.Strings(keys)

sortedMap := make(map[string][]*fiber.Route)
for _, k := range keys {
sortedMap[k] = m[k]
}

return keys, sortedMap
return keys
}

0 comments on commit 47114ba

Please sign in to comment.