diff options
Diffstat (limited to 'model/validation.go')
-rw-r--r-- | model/validation.go | 28 |
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 +} |