Playing with generic maps

This commit is contained in:
Dan Buch 2012-12-25 00:07:26 -05:00
parent c8b4612c2e
commit 887919098f
2 changed files with 38 additions and 0 deletions

View File

@ -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 \

View File

@ -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"])
}