summaryrefslogtreecommitdiff
path: root/model/validation.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-17 17:12:50 +0200
committerxengineering <me@xengineering.eu>2024-05-17 17:14:40 +0200
commit5eca3267d37cdc51f775b5452727efebbb7e7e9e (patch)
treec80dd1512270386e3912beeb05bda3347a464e36 /model/validation.go
parent0416f520cff9716792ac0f3ade5f71187d07ac2e (diff)
downloadceres-5eca3267d37cdc51f775b5452727efebbb7e7e9e.tar
ceres-5eca3267d37cdc51f775b5452727efebbb7e7e9e.tar.zst
ceres-5eca3267d37cdc51f775b5452727efebbb7e7e9e.zip
model: Rework recipe validation
This reduces code duplication and enforces time stamps.
Diffstat (limited to 'model/validation.go')
-rw-r--r--model/validation.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/model/validation.go b/model/validation.go
new file mode 100644
index 0000000..d49141d
--- /dev/null
+++ b/model/validation.go
@@ -0,0 +1,28 @@
+package model
+
+import (
+ "fmt"
+ "strconv"
+)
+
+func isInt(s string) error {
+ _, err := strconv.Atoi(s)
+ if err != nil {
+ return fmt.Errorf("'%s' cannot be casted to integer", s)
+ }
+
+ return nil
+}
+
+func isPositiveOrZeroInt(s string) error {
+ i, err := strconv.Atoi(s)
+ if err != nil {
+ return fmt.Errorf("'%s' cannot be casted to integer", s)
+ }
+
+ if i < 0 {
+ return fmt.Errorf("'%s' is negative", s)
+ }
+
+ return nil
+}