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")
}

View File

@@ -24,7 +24,7 @@ const weightcolumns = "rowid, date, weight"
const weightAggregatedColumns = "period, amount"
func (w *WeightService) GetRecent() ([]Weight, error) {
var res []Weight
res := []Weight{}
if w.db == nil || !w.db.Ready {
return res, fmt.Errorf("cannot get recent weight, db is nil or is not ready")
}
@@ -88,7 +88,7 @@ func (w *WeightService) GetByRowid(rowid int64) (Weight, error) {
// I could probably refactor this to be less of a disaster...
// But I think it'll work for now
func (w *WeightService) GetDaily() ([]AggregatedWeight, error) {
var res []AggregatedWeight
res := []AggregatedWeight{}
if w.db == nil || !w.db.Ready {
return res, fmt.Errorf("cannot get daily weight, db is nil or is not ready")
}
@@ -114,7 +114,7 @@ func (w *WeightService) GetDaily() ([]AggregatedWeight, error) {
}
func (w *WeightService) GetWeekly() ([]AggregatedWeight, error) {
var res []AggregatedWeight
res := []AggregatedWeight{}
if w.db == nil || !w.db.Ready {
return res, fmt.Errorf("cannot get weekly weight, db is nil or is not ready")
}
@@ -140,7 +140,7 @@ func (w *WeightService) GetWeekly() ([]AggregatedWeight, error) {
}
func (w *WeightService) GetMonthly() ([]AggregatedWeight, error) {
var res []AggregatedWeight
res := []AggregatedWeight{}
if w.db == nil || !w.db.Ready {
return res, fmt.Errorf("cannot get monthly weight, db is nil or is not ready")
}
@@ -166,7 +166,7 @@ func (w *WeightService) GetMonthly() ([]AggregatedWeight, error) {
}
func (w *WeightService) GetYearly() ([]AggregatedWeight, error) {
var res []AggregatedWeight
res := []AggregatedWeight{}
if w.db == nil || !w.db.Ready {
return res, fmt.Errorf("cannot get yearly weight, db is nil or is not ready")
}