Initial Commit

This commit is contained in:
Brian Buller 2017-11-15 13:11:34 -06:00
parent 3bff65b30c
commit 822f30394a
2 changed files with 52 additions and 0 deletions

8
main.go Normal file
View File

@ -0,0 +1,8 @@
package main
import "fmt"
func main() {
r := Recipe{Name:"Bread"}
fmt.Println("Done: "+r.Name)
}

44
recipes.go Normal file
View File

@ -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)
}