Fix go services returning nulls

I did not know that var foo []bar does not initialize foo to empty []!
Fuck
This commit is contained in:
2024-08-13 18:17:39 +02:00
parent 0e64ff9eb2
commit 0051ae71d9
2 changed files with 10 additions and 10 deletions

View File

@@ -35,7 +35,7 @@ const foodColumns = "rowid, date, food, description, amount, per100, energy"
const foodAggregatedColumns = "period, amount, avgPer100, energy"
func (s *FoodService) GetRecent() ([]Food, error) {
var res []Food
var res []Food = []Food{}
if s.db == nil || !s.db.Ready {
return res, fmt.Errorf("cannot get recent food, db is nil or is not ready")
}
@@ -183,7 +183,7 @@ func (s *FoodService) GetByRowid(rowid int64) (Food, error) {
// I could probably refactor this to be less of a disaster...
// But I think it'll work for now
func (s *FoodService) GetDaily() ([]AggregatedFood, error) {
var res []AggregatedFood
res := []AggregatedFood{}
if s.db == nil || !s.db.Ready {
return res, fmt.Errorf("cannot get daily food, db is nil or is not ready")
}
@@ -209,7 +209,7 @@ func (s *FoodService) GetDaily() ([]AggregatedFood, error) {
}
func (s *FoodService) GetWeekly() ([]AggregatedFood, error) {
var res []AggregatedFood
res := []AggregatedFood{}
if s.db == nil || !s.db.Ready {
return res, fmt.Errorf("cannot get weekly food, db is nil or is not ready")
}
@@ -235,7 +235,7 @@ func (s *FoodService) GetWeekly() ([]AggregatedFood, error) {
}
func (s *FoodService) GetMonthly() ([]AggregatedFood, error) {
var res []AggregatedFood
res := []AggregatedFood{}
if s.db == nil || !s.db.Ready {
return res, fmt.Errorf("cannot get monthly food, db is nil or is not ready")
}
@@ -261,7 +261,7 @@ func (s *FoodService) GetMonthly() ([]AggregatedFood, error) {
}
func (s *FoodService) GetYearly() ([]AggregatedFood, error) {
var res []AggregatedFood
res := []AggregatedFood{}
if s.db == nil || !s.db.Ready {
return res, fmt.Errorf("cannot get yearly food, db is nil or is not ready")
}