-
Notifications
You must be signed in to change notification settings - Fork 0
/
meal_item.go
48 lines (41 loc) · 1.17 KB
/
meal_item.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
Package food implements classes that are used for meal planning and calorie
counting.
It will reuse the naming conventions established by schema.org.
- https://schema.org/Recipe
- https://schema.org/NutritionInformation
*/
package mealitem
import (
"fmt"
"math"
)
// https://schema.org/NutritionInformation
type Nutrition struct {
Calories string // <Number> <Energy unit of measure>
CarbohydrateContent string // <Number> <Mass unit of measure> -> in gram
FatContent string // <Number> <Mass unit of measure> -> in gram
ProteinContent string // <Number> <Mass unit of measure> -> in gram
}
// https://schema.org/Recipe
type MealItem struct {
ID int64
Name string
Calories int
Carbs int
Fat int
Protein int
Nutrition *Nutrition
}
func NewMealItem(name string, calories, carbs, fat, protein float64) *MealItem {
item := &MealItem{
Name: name,
Nutrition: &Nutrition{
Calories: fmt.Sprintf("%d kcal", int(math.Round(calories))),
FatContent: fmt.Sprintf("%.1f g", fat),
CarbohydrateContent: fmt.Sprintf("%.1f g", carbs),
ProteinContent: fmt.Sprintf("%.1f g", protein),
},
}
return item
}