Comments (3)
I've just found and example here.
https://go-macaron.com/docs/middlewares/binding
from binding.
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 ?
from binding.
Hi @unknwon after recompile again validations began working ok!
Thank you
from binding.
Related Issues (20)
- Unicode support
- Cannot apply validation rule to pointer field *string
- Related resource validation? HOT 1
- parsing errors from setWithProperType never get bubbled up
- 无法解析数组参数 HOT 10
- Error on upload Files - no data sent to the handler. HOT 7
- 建议增加设置,可自定义 binding 标识 HOT 5
- Custom validation on the documentation can not be compiled (undefined "rule" error). HOT 2
- Error In Validation "In()" also implies Required HOT 1
- [Feature Request] Enable macaron binding Validation outside a request context. HOT 3
- Multiple sub-forms from html not json ? HOT 2
- Security checks for Json() HOT 3
- 建议可以自定义默认的errorHandler HOT 1
- Pls upd mod vendor as in main macaron package HOT 2
- case-insensitive import collision: "github.com/unknwon/com" and "github.com/Unknwon/com" HOT 1
- GET requests with content-type header set result in errors HOT 3
- Add unit tests for `binding.URL`
- 纯ip格式可以通过binding.Url校验
- Called inject.InterfaceOf with a value that is not a pointer to an interface. (*MyInterface)(nil)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from binding.