aboutsummaryrefslogtreecommitdiff
path: root/content/maps/people.go
diff options
context:
space:
mode:
Diffstat (limited to 'content/maps/people.go')
-rw-r--r--content/maps/people.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/content/maps/people.go b/content/maps/people.go
new file mode 100644
index 0000000..ff5d9e3
--- /dev/null
+++ b/content/maps/people.go
@@ -0,0 +1,34 @@
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build OMIT
+
+package main
+
+import "fmt"
+
+func main() {
+ // START1 OMIT
+ type Person struct {
+ Name string
+ Likes []string
+ }
+ var people []*Person
+
+ likes := make(map[string][]*Person) // HL
+ for _, p := range people {
+ for _, l := range p.Likes {
+ likes[l] = append(likes[l], p) // HL
+ }
+ }
+ // END1 OMIT
+
+ // START2 OMIT
+ for _, p := range likes["cheese"] {
+ fmt.Println(p.Name, "likes cheese.")
+ }
+ // END2 OMIT
+
+ fmt.Println(len(likes["bacon"]), "people like bacon.")
+}