-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yoyofx
committed
May 10, 2021
1 parent
c6413ef
commit cace77d
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## 参考Gin, 并与Gin Binding & Valvalidate API 保持一致. | ||
```go | ||
// 绑定为json | ||
type Login struct { | ||
User string `form:"user" json:"user" xml:"user" binding:"required"` | ||
Password string `form:"password" json:"password" xml:"password" binding:"required"` | ||
} | ||
|
||
// Example for binding JSON ({"user": "manu", "password": "123"}) | ||
err := ctx.Bind(Login) | ||
``` | ||
```bash | ||
curl -v -X POST \ | ||
http://localhost:8080/loginJSON \ | ||
-H 'content-type: application/json' \ | ||
-d '{ "user": "manu" }' | ||
``` | ||
|
||
##跳过验证: | ||
当使用上面的curl命令运行上面的示例时,返回错误,因为示例中Password字段使用了binding:"required",如果我们使用binding:"-",那么它就不会报错。 |