feat(context): add BindQuery func (#1029)
* feat(context): add BindQuery func, only parse/bind the query string params. * docs(readme): add BindQuery section. * docs(readme): fix import. * docs(readme): separate import
This commit is contained in:
committed by
Javier Provecho Fernandez
parent
74221b8a35
commit
c19aa0598b
38
README.md
38
README.md
@ -460,7 +460,43 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Bind Query String
|
||||
### Only Bind Query String
|
||||
|
||||
`BindQuery` function only binds the query params and not the post data. See the [detail information](https://github.com/gin-gonic/gin/issues/742#issuecomment-315953017).
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
Name string `form:"name"`
|
||||
Address string `form:"address"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
route := gin.Default()
|
||||
route.Any("/testing", startPage)
|
||||
route.Run(":8085")
|
||||
}
|
||||
|
||||
func startPage(c *gin.Context) {
|
||||
var person Person
|
||||
if c.BindQuery(&person) == nil {
|
||||
log.Println("====== Only Bind By Query String ======")
|
||||
log.Println(person.Name)
|
||||
log.Println(person.Address)
|
||||
}
|
||||
c.String(200, "Success")
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### Bind Query String or Post Data
|
||||
|
||||
See the [detail information](https://github.com/gin-gonic/gin/issues/742#issuecomment-264681292).
|
||||
|
||||
|
Reference in New Issue
Block a user