Playing with generic maps
This commit is contained in:
parent
c8b4612c2e
commit
887919098f
@ -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 \
|
||||
|
37
gotime/gotour-artifacts/generic-maps/main.go
Normal file
37
gotime/gotour-artifacts/generic-maps/main.go
Normal 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"])
|
||||
}
|
Loading…
Reference in New Issue
Block a user