summaryrefslogtreecommitdiff
path: root/model/validation.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-15 20:18:39 +0200
committerxengineering <me@xengineering.eu>2024-05-17 23:20:41 +0200
commitbc149ee58122effc9d4c035da2af3a7ec1f2f862 (patch)
treeca58dac0b34ad771ef0821a2de887171d985d94d /model/validation.go
parentf8f5d296f218f79646a54d3aed8d54fa9f8704c1 (diff)
downloadceres-bc149ee58122effc9d4c035da2af3a7ec1f2f862.tar
ceres-bc149ee58122effc9d4c035da2af3a7ec1f2f862.tar.zst
ceres-bc149ee58122effc9d4c035da2af3a7ec1f2f862.zip
model: Add strict Ingredient.Validate()
Diffstat (limited to 'model/validation.go')
-rw-r--r--model/validation.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/model/validation.go b/model/validation.go
index d49141d..ac38777 100644
--- a/model/validation.go
+++ b/model/validation.go
@@ -26,3 +26,16 @@ func isPositiveOrZeroInt(s string) error {
return nil
}
+
+func isPositiveOrZeroFloat(s string) error {
+ f, err := strconv.ParseFloat(s, 32)
+ if err != nil {
+ return fmt.Errorf("'%s' cannot be casted to floating point number", s)
+ }
+
+ if f < 0 {
+ return fmt.Errorf("'%s' is negative", s)
+ }
+
+ return nil
+}