base safe
This commit is contained in:
41
foodlist/foodlist.go
Normal file
41
foodlist/foodlist.go
Normal file
@ -0,0 +1,41 @@
|
||||
package foodlist
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/csv"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// FoodOfTheDay is the food list of the day
|
||||
type FoodOfTheDay struct {
|
||||
Date string
|
||||
Foods []Food
|
||||
}
|
||||
|
||||
// Food is a type of food
|
||||
type Food struct {
|
||||
Title string
|
||||
Icon string
|
||||
}
|
||||
|
||||
// GetFoodOfTheDay return the list of food of the day
|
||||
func GetFoodOfTheDay(Today string) FoodOfTheDay {
|
||||
foodcsv, _ := os.Open("foodlist/foods.csv")
|
||||
foodreader := csv.NewReader(bufio.NewReader(foodcsv))
|
||||
foods := FoodOfTheDay{}
|
||||
for {
|
||||
line, err := foodreader.Read()
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
food := Food{line[0], line[1]}
|
||||
foods.Foods = append(foods.Foods, food)
|
||||
}
|
||||
foods.Date = Today
|
||||
|
||||
return foods
|
||||
}
|
8
foodlist/foods.csv
Normal file
8
foodlist/foods.csv
Normal file
@ -0,0 +1,8 @@
|
||||
sandwich,🥪
|
||||
sushi,🍣
|
||||
burger,🍔
|
||||
tacos,🌯
|
||||
italien,🍝
|
||||
kebab,🥙
|
||||
pizza,🍕
|
||||
hotdog,🌭
|
|
Reference in New Issue
Block a user