package main
import "fmt"
type Product struct {
name string
price float32
}
func main() {
var products = make(map[string]Product)
products["p01"] = Product{
name: "Name 1",
price: 5.6,
}
products["p02"] = Product{
name: "Name 2",
price: 7.8,
}
products["p03"] = Product{
name: "Name 3",
price: 8.1,
}
fmt.Println("Product List")
for id, product := range products {
fmt.Println("id:", id)
fmt.Println("name:", product.name)
fmt.Println("price:", product.price)
fmt.Println("------------------")
}
}
Product List
id: p02
name: Name 2
price: 7.8
------------------
id: p03
name: Name 3
price: 8.1
------------------
id: p01
name: Name 1
price: 5.6
------------------