From 887919098fdd196b5222a93969bfe1ba844a3e4e Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 25 Dec 2012 00:07:26 -0500 Subject: [PATCH] Playing with generic maps --- gotime/Makefile | 1 + gotime/gotour-artifacts/generic-maps/main.go | 37 ++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 gotime/gotour-artifacts/generic-maps/main.go diff --git a/gotime/Makefile b/gotime/Makefile index 1e8c71d..9f8a2e6 100644 --- a/gotime/Makefile +++ b/gotime/Makefile @@ -9,6 +9,7 @@ TARGETS = \ github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/exercise-rot13-reader \ github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/exercise-slices \ github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/exercise-sqrt \ + github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/generic-maps \ github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/goroutines \ github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/hello-web \ github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/maps \ diff --git a/gotime/gotour-artifacts/generic-maps/main.go b/gotime/gotour-artifacts/generic-maps/main.go new file mode 100644 index 0000000..c7092ae --- /dev/null +++ b/gotime/gotour-artifacts/generic-maps/main.go @@ -0,0 +1,37 @@ +package main + +import ( + "fmt" + "time" +) + +type Shoe struct { + Hamsters uint8 + Tacos []string +} + +type Cheese struct { + Holes float64 + Flavors map[string]string + ShelfLife time.Time +} + +func main() { + v := make(map[string]interface{}) + v["loafer"] = &Shoe{ + Hamsters: uint8(49), + Tacos: []string{"spicy", "crunchy"}, + } + flavors := make(map[string]string) + flavors["fruit01"] = "grape" + flavors["fruit02"] = "apple" + v["cheddar"] = &Cheese{ + Holes: float64(9.2), + Flavors: flavors, + ShelfLife: time.Date(1999, time.Month(8), 12, 7, 15, 22, 0, time.UTC), + } + + fmt.Printf("v = %+v\n", v) + fmt.Printf("v[\"loafer\"] = %+v\n", v["loafer"]) + fmt.Printf("v[\"cheddar\"] = %+v\n", v["cheddar"]) +}