From eafa073f711942464907766859e5b3b93d921e8f Mon Sep 17 00:00:00 2001 From: Eason Lin Date: Tue, 18 Jul 2017 12:27:57 +0800 Subject: [PATCH] docs(readme): add BindQuery section. --- README.md | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 211ed59d..40eaa1c0 100644 --- a/README.md +++ b/README.md @@ -454,7 +454,42 @@ 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" +import ( + "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).