-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmap.go
More file actions
42 lines (37 loc) · 756 Bytes
/
map.go
File metadata and controls
42 lines (37 loc) · 756 Bytes
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
34
35
36
37
38
39
40
41
42
package main
import (
"log"
"sort"
)
func sortUniqueKeys(maps ...map[string]string) (unique []string) {
combined := make(map[string]struct{})
for _, m := range maps {
for key := range m {
combined[key] = struct{}{}
}
}
for key := range combined {
unique = append(unique, key)
}
sort.Strings(unique)
return unique
}
func mapKeys(m map[string]string) (keys []string) {
for key := range m {
keys = append(keys, key)
}
sort.Strings(keys)
return keys
}
func printMapKeys(m map[string]string, preamble string) {
printStrings(mapKeys(m), preamble)
}
func printStrings(paths []string, preamble string) {
log.Printf(preamble, len(paths))
if len(paths) == 0 {
return
}
for _, path := range paths {
log.Println(" " + path)
}
}