forked from Lyoness/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example2.go
41 lines (31 loc) · 866 Bytes
/
example2.go
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
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// Sample program to show how to declare and initialize a map
// using a map literal and delete a key.
package main
import "fmt"
// user defines a user in the program.
type user struct {
name string
surname string
}
func main() {
// Declare and initialize the map with values.
users := map[string]user{
"Roy": {"Rob", "Roy"},
"Ford": {"Henry", "Ford"},
"Mouse": {"Mickey", "Mouse"},
"Jackson": {"Michael", "Jackson"},
}
// Iterate over the map.
for key, value := range users {
fmt.Println(key, value)
}
// Delete the Roy key.
delete(users, "Roy")
fmt.Println("=================")
// Find the Roy key.
u, found := users["Roy"]
// Display the value and found flag.
fmt.Println("Roy", found, u)
}