Skip to content

Commit

Permalink
Add ordered in printing
Browse files Browse the repository at this point in the history
  • Loading branch information
lotusirous committed Dec 13, 2021
1 parent 311cd11 commit bdc0e90
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import (
"io"
"os"
"path/filepath"
"sort"
)

// HashGroup composes the name to hash hash function
type HashGroup map[string]hash.Hash

// Values extracts the values from group hash.
func (h HashGroup) Values() map[string]string {
out := make(map[string]string)
for name, v := range h {
Expand Down Expand Up @@ -119,8 +121,15 @@ func main() {
fmt.Fprintf(fd, "Cannot digest: %v", err)
os.Exit(1)
}
for name, v := range hashes {
fmt.Fprintf(fd, "%s: %s\n", name, v)
// sort by key since the go map is unordered
keys := make([]string, 0, len(hashes))
for k := range hashes {
keys = append(keys, k)
}
sort.Strings(keys)

for _, name := range keys {
fmt.Fprintf(fd, "%s: %s\n", name, hashes[name])
}
}

Expand Down

0 comments on commit bdc0e90

Please sign in to comment.