From 47114baddc672e3d1d58d36fbc75a3c27588ea0e Mon Sep 17 00:00:00 2001 From: LE VAN THANH Date: Tue, 15 Nov 2022 17:15:03 +0700 Subject: [PATCH] simpler functions --- main.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index d55f0b0..28eb5f1 100644 --- a/main.go +++ b/main.go @@ -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) @@ -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 }