Initial Commit
This commit is contained in:
parent
3bff65b30c
commit
822f30394a
8
main.go
Normal file
8
main.go
Normal 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
44
recipes.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user