From fe3034818d3d0242b0457800fd1a778f8aa53185 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 2 Oct 2018 12:00:57 +0200 Subject: [PATCH] add 'id' (positive 'int') type checker --- internal/checker/default/id/main.go | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 internal/checker/default/id/main.go diff --git a/internal/checker/default/id/main.go b/internal/checker/default/id/main.go new file mode 100644 index 0000000..62df3ed --- /dev/null +++ b/internal/checker/default/id/main.go @@ -0,0 +1,30 @@ +package main + +import ( + "git.xdrm.io/go/aicra/driver" + "math" +) + +func main() {} +func Export() driver.Checker { return new(IdChecker) } + +type IdChecker int + +// Match matches the string 'id' +func (ick IdChecker) Match(name string) bool { + return name == "id" +} + +// Check returns true for any type from the @validationTable +func (ick IdChecker) Check(value interface{}) bool { + + // check if float (default wrapping type) + floatVal, ok := value.(float64) + if !ok { + return false + } + + // check if there is no floating point + return floatVal == math.Floor(floatVal) && floatVal > 0 + +}