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
govalstag 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=22validate length of string or intemailvalidate string of emaildatevalidate date of string if match, like 09-12-1996 or 09/12/1996timevalidate time if match, like 12:00:01 or 12:01alphavalidate string if contains alpha characternumericvalidate string if contains numericalphaNumericvalidate string if contains alpha numeric characterphonevalidate string if valid phone number formatcustomvalidate custom rule, using regexp, you can write your own rule to validate data