39 lines
581 B
Go
39 lines
581 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
type FoodEntry struct {
|
|
Name string
|
|
Calories float32
|
|
}
|
|
|
|
type ReportEntry struct {
|
|
Entry FoodEntry
|
|
Weight int
|
|
}
|
|
|
|
type Report struct {
|
|
Date string
|
|
Food []ReportEntry
|
|
}
|
|
|
|
func SplitReport(report string) []string {
|
|
listOfEntries := strings.Split(report, "\n")
|
|
return listOfEntries
|
|
}
|
|
|
|
func main() {
|
|
report, err := os.ReadFile("main_testdata")
|
|
if err != nil {
|
|
fmt.Print("Something went wrong")
|
|
}
|
|
str := string(report)
|
|
result := SplitReport(str)
|
|
for _, element := range result {
|
|
fmt.Println("Entry: ", element)
|
|
}
|
|
}
|