-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.go
47 lines (41 loc) · 1.04 KB
/
utils.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
package main
import (
"math"
"strings"
)
var SortByOptions = []string{"cost", "calories", "caloriesfromfat",
"totalfat", "saturatedfat", "transfat", "cholesterol", "sodium", "totalcarbohydrates", "dietaryfiber",
"sugars", "protein"}
func round(num float64) int {
return int(num + math.Copysign(0.5, num))
}
func toFixed(num float64, precision int) float64 {
output := math.Pow(10, float64(precision))
return float64(round(num * output)) / output
}
func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
func getPropertyName(name string) string {
name = strings.ToLower(name);
var properties = map[string]string{
"cost": "Cost",
"calories": "Calories",
"caloriesfromfat": "CaloriesFromFat",
"totalfat": "TotalFat",
"saturatedfat": "SaturatedFat",
"transfat": "TransFat",
"cholesterol": "Cholesterol",
"sodium": "Sodium",
"carbohydrates": "Carbohydrates",
"dietaryfiber": "DietaryFiber",
"sugars": "Sugars",
"protein": "Protein",
};
return properties[name]
}