Problem:
- Want to read data from CSV file and group it based on this combination
warehouse[item[batch, qty]]
- [Batch, Qty] pair should be inserted in sequence
Approach:
- I thought best way to make it is to use a combination of
map
andpair/tuple
Code:
package main
import "fmt"
type Pair struct {
Key string
Value float64
}
func main() {
fmt.Println("Hello, δΈη")
var inventory = map[string]map[string][]Pair{} //warehouse[item[batch, qty]]
fmt.Printf("%T\n", inventory)
inventory["DMM"] = map[string][]Pair{} // map[string]map[string][]main.Pair
fmt.Printf("%T\n", inventory["DMM"])
inventory["DMM"]["Helmet"] = []Pair{}
fmt.Printf("%T = %v\n", inventory["DMM"]["Helmet"])
inventory["DMM"]["Helmet"] = append(inventory["DMM"]["Helmet"], Pair{"Jan", 10})
fmt.Printf("%T = %v\n", inventory["DMM"]["Helmet"][0])
}
Code error
Hello, δΈη
map[string]map[string][]main.Pair
map[string][]main.Pair
[]main.Pair = %!v(MISSING)
main.Pair = %!v(MISSING)
Notes
- It looks I was able to enter the
warehouse
anditem
combination correctly, but something not correct for entering/inserting/adding/appending thePair
to this combination!