forked from ardanlabs/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example2.go
46 lines (34 loc) · 807 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
42
43
44
45
46
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// http://play.golang.org/p/GF0gbY4SvN
// Sample program to show the properties of nil maps.
package main
import "fmt"
// main is the entry point for the application.
func main() {
show(map[int]string{1: "one", 2: "two", 3: "three"})
fmt.Println()
show(nil)
}
func show(m map[int]string) {
defer func() {
v := recover()
if v != nil {
fmt.Println("FAILED:", v)
}
}()
fmt.Printf("Checking: %#v\n", m)
fmt.Print("Iteration ... ")
for range m {
}
fmt.Println("OK")
fmt.Print("Key Read ... ")
_ = m[23]
fmt.Println("OK")
fmt.Print("Deletion ... ")
delete(m, 23)
fmt.Println("OK")
fmt.Print("Key Assignment ... ")
m[4] = "four"
fmt.Println("OK")
}