From 3feb5578dd8c9e3d6e04211d78df541ffd50440c Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Mon, 25 May 2015 21:15:52 -0700 Subject: [PATCH 1/4] add querystring parameter example to readme --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index c8fe60e..1ae003e 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,24 @@ func main() { r.Run(":8080") } ``` + +#### Querystring parameters +```go +func main() { + r := gin.Default() + + // Query string parameters are parsed used the existing underlying request object. + // The request responds to a url matching: /search?firstname=Jane&lastname=Doe + r.GET("/search", func(c *gin.Context) { + firstname := c.Request.URL.Query().Get("latitude") + lastname := c.Request.URL.Quert().Get("longitude") + message := "Hello " + firstname + lastname + c.String(http.StatusOK, message) + }) + r.Run(":8080") +} +``` + ###Form parameters ```go func main() { From f8d34ac8b6e378909fd3c5e64cbee4a33cfa444c Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Mon, 25 May 2015 21:17:23 -0700 Subject: [PATCH 2/4] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1ae003e..594b065 100644 --- a/README.md +++ b/README.md @@ -149,8 +149,8 @@ func main() { // Query string parameters are parsed used the existing underlying request object. // The request responds to a url matching: /search?firstname=Jane&lastname=Doe r.GET("/search", func(c *gin.Context) { - firstname := c.Request.URL.Query().Get("latitude") - lastname := c.Request.URL.Quert().Get("longitude") + firstname := c.Request.URL.Query().Get("firstname") + lastname := c.Request.URL.Quert().Get("lastname") message := "Hello " + firstname + lastname c.String(http.StatusOK, message) }) From 8d812a2097176975292b7c9fbc5f7dabbee63dae Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Mon, 25 May 2015 21:19:02 -0700 Subject: [PATCH 3/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 594b065..d6d11d2 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ func main() { func main() { r := gin.Default() - // Query string parameters are parsed used the existing underlying request object. + // Query string parameters are parsed using the existing underlying request object. // The request responds to a url matching: /search?firstname=Jane&lastname=Doe r.GET("/search", func(c *gin.Context) { firstname := c.Request.URL.Query().Get("firstname") From b7253902d0692c08f662b3a740d746ca5e223a72 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Tue, 26 May 2015 08:11:20 -0700 Subject: [PATCH 4/4] Update README.md --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d6d11d2..ffe43c8 100644 --- a/README.md +++ b/README.md @@ -144,17 +144,17 @@ func main() { #### Querystring parameters ```go func main() { - r := gin.Default() - - // Query string parameters are parsed using the existing underlying request object. - // The request responds to a url matching: /search?firstname=Jane&lastname=Doe - r.GET("/search", func(c *gin.Context) { - firstname := c.Request.URL.Query().Get("firstname") - lastname := c.Request.URL.Quert().Get("lastname") - message := "Hello " + firstname + lastname - c.String(http.StatusOK, message) - }) - r.Run(":8080") + router := gin.Default() + + // Query string parameters are parsed using the existing underlying request object. + // The request responds to a url matching: /welcome?firstname=Jane&lastname=Doe + router.GET("/welcome", func(c *gin.Context) { + firstname := c.DefaultQuery("firstname", "Guest") + lastname := c.Query("lastname") // shortcut for c.Request.URL.Query().Get("lastname") + + c.String(http.StatusOK, "Hello %s %s", firstname, lastname) + }) + router.Run(":8080") } ```