From e83cf561266af846e9a81089c5ddcf2546ea2b01 Mon Sep 17 00:00:00 2001 From: qowevisa Date: Sun, 1 Dec 2024 12:37:29 +0200 Subject: [PATCH] Add consts.go to db package and move all Metric values to consts.go --- db/consts.go | 8 ++++++++ db/db.go | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 db/consts.go diff --git a/db/consts.go b/db/consts.go new file mode 100644 index 0000000..9fa9642 --- /dev/null +++ b/db/consts.go @@ -0,0 +1,8 @@ +package db + +const ( + METRIC_VALUE_NONE = 0 + iota + METRIC_VALUE_GRAM + METRIC_VALUE_KILOGRAM + METRIC_VALUE_LITER +) diff --git a/db/db.go b/db/db.go index 1ae82fe..c37a493 100644 --- a/db/db.go +++ b/db/db.go @@ -107,10 +107,10 @@ func checkSeededValues[T Identifiable](whatToCheck []*T, errorIfNotFound error, func initMetrics(tx *gorm.DB) error { metricsThatNeeded := []*Metric{ - &Metric{Name: "None", Short: "pcs", Value: 0}, - &Metric{Name: "Gram", Short: "g", Value: 1}, - &Metric{Name: "Kilogram", Short: "kg", Value: 2}, - &Metric{Name: "Liter", Short: "l", Value: 3}, + &Metric{Name: "None", Short: "pcs", Value: METRIC_VALUE_NONE}, + &Metric{Name: "Gram", Short: "g", Value: METRIC_VALUE_GRAM}, + &Metric{Name: "Kilogram", Short: "kg", Value: METRIC_VALUE_KILOGRAM}, + &Metric{Name: "Liter", Short: "l", Value: METRIC_VALUE_LITER}, } return checkSeededValues(metricsThatNeeded, CANT_FIND_METRIC, tx) }