Govals is a go/golang package for validate data, using struct and etc. govals have custom function like validate email, numeric, alpha, alpha numeric, date, time, phone number, and length of int or string, i hope soon i will add more function for validate data.
example how to use govals, you can open folder example
Run this command go get github.com/fn-code/govals
to use this library
-
this is basic function you can use to validate your data:
ok, err := govals.Length(1000, 2, 10) if err != nil { log.Println(err) } if !ok { // bla bla bla }
-
in struct you can use
govals
tag like this:Name string `govals:"len, max=22, min=10"` Age int8 `govals:"len, min=18, max=20"` Email string `govals:"email"` Date string `govals:"date"` Times string `govals:"time"` Hoby string `govals:"alpha"` Max string `govals:"numeric"` Text string `govals:"alphaNumeric"` Phone string `govals:"phone"` Address string `govals:"custom, regex=[^(a-zA-Z)]"`
len, min=10, max=22
validate length of string or intemail
validate string of emaildate
validate date of string if match, like 09-12-1996 or 09/12/1996time
validate time if match, like 12:00:01 or 12:01alpha
validate string if contains alpha characternumeric
validate string if contains numericalphaNumeric
validate string if contains alpha numeric characterphone
validate string if valid phone number formatcustom
validate custom rule, using regexp, you can write your own rule to validate data