diff --git a/main.go b/main.go new file mode 100644 index 0000000..95401a8 --- /dev/null +++ b/main.go @@ -0,0 +1,8 @@ +package main + +import "fmt" + +func main() { + r := Recipe{Name:"Bread"} + fmt.Println("Done: "+r.Name) +} diff --git a/recipes.go b/recipes.go new file mode 100644 index 0000000..6cff260 --- /dev/null +++ b/recipes.go @@ -0,0 +1,44 @@ +package main + +type Ingredient struct { + Name string + Parts []Ingredient + Location string + Notes []string +} + +type RecipeIngredient struct { + Ingredient + Quantity int +} + +type Recipe struct { + Name string + Parts []RecipeIngredient + Notes []string +} + +func NewRecipe(nm string) *Recipe { + ret := Recipe{Name: nm} +} + +func (r *Recipe) AddNote(nt string) { + r.Notes = append(r.Notes, nt) +} + +func (r *Recipe) AddIngredient(i *Ingredient, qty int) { + for i := range r.Parts { + if r.Parts[i].Name == i.Name { + // This ingredient is already a party of the recipe + r.Parts[i].Quantity += qty + return + } + } + ing := new(RecipeIngredient) + ing.Name = i.Name + ing.Parts = i.Parts + ing.Location = i.Location + ing.Quantity = qty + ing.Notes = i.Notes + r.Parts = append(r.Parts, ing) +}