package models import "time" type Cake struct { Name string ID int Price Price // increments of 0.01 Amount int } type Order struct { ID int Name string Surname string Phone string Location string Date time.Time Accepted time.Time Status string Paid Price // increments of 0.01 Cakes []Cake } func (o *Order) Subtotal() Price { var out Price for _, e := range o.Cakes { out += e.Price * Price(e.Amount) } return out } func (o *Order) Total() Price { return o.Subtotal() - o.Paid } func (c *Cake) Total() Price { return Price(c.Amount) * c.Price }