-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regex Validation examples? #19
Comments
I've just found and example here. |
Hi @unknwon I'm trying to add validation for my binding struct, adding the "binding" tag // SnmpDeviceCfg contains all snmp related device definitions
type SnmpDeviceCfg struct {
ID string `xorm:"'id' unique" binding:"Required"`
Host string `xorm:"host" binding:"Required"`
Port int `xorm:"port" binding:"Required"`
....
.....
} And this is my url definition (https://github.com/toni-moreno/snmpcollector/blob/master/pkg/webui/apicfg-snmpdevice.go#L17) and my AddDevice handler (https://github.com/toni-moreno/snmpcollector/blob/master/pkg/webui/apicfg-snmpdevice.go#L40-L50) When I have sent this simple json.on the API url {"ID":"test4"} The deserialization has been done correctly although required fields like "host" "port" has been defined and there are not in the input Where is the error? why binding.Bind is not validating this incorrect input json ? |
Hi @unknwon after recompile again validations began working ok! |
I've looked for example on validate a a binded struct like that, (https://github.com/toni-moreno/snmpcollector/blob/master/pkg/config/sqlconfig.go#L6-L46).
This is all what I've found (https://gowalker.org/github.com/go-macaron/binding#Validate). Could you show me an example on how should i use validation ,type validation with regex , by example ?
Thank you very much
The text was updated successfully, but these errors were encountered: