Skip to content

Commit

Permalink
README.md for binding
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyofx committed May 10, 2021
1 parent c6413ef commit cace77d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions web/binding/README.md
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:"-",那么它就不会报错。

0 comments on commit cace77d

Please sign in to comment.