-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.go
More file actions
36 lines (31 loc) · 758 Bytes
/
Copy pathmenu.go
File metadata and controls
36 lines (31 loc) · 758 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
package main
import (
"fmt"
"sort"
)
var menuItems map[string]Option = map[string]Option{
"1": add,
"2": view,
"3": edit,
"4": delete,
}
// menu prints out the program's main menu and all the possible
// options a user can enter
func printMenu() {
sortedMenuItems := sortMenuItems(menuItems)
for _, k := range sortedMenuItems {
fmt.Printf("%s. %s\n", k, menuItems[k].Description)
}
fmt.Println("\nOr enter 'q' to exit the program.")
fmt.Print("Your option: ")
}
// sortMenuItems adds the menuItems map to a slice of strings
// then sorts the slice and returns it
func sortMenuItems(menuItems map[string]Option) []string {
keys := make([]string, 0)
for k := range menuItems {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}