Update README.md

This commit is contained in:
Justin Beckwith 2015-05-26 08:11:20 -07:00
parent 8d812a2097
commit b7253902d0

View File

@ -144,17 +144,17 @@ func main() {
#### Querystring parameters #### Querystring parameters
```go ```go
func main() { func main() {
r := gin.Default() router := gin.Default()
// Query string parameters are parsed using 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 // The request responds to a url matching: /welcome?firstname=Jane&lastname=Doe
r.GET("/search", func(c *gin.Context) { router.GET("/welcome", func(c *gin.Context) {
firstname := c.Request.URL.Query().Get("firstname") firstname := c.DefaultQuery("firstname", "Guest")
lastname := c.Request.URL.Quert().Get("lastname") lastname := c.Query("lastname") // shortcut for c.Request.URL.Query().Get("lastname")
message := "Hello " + firstname + lastname
c.String(http.StatusOK, message) c.String(http.StatusOK, "Hello %s %s", firstname, lastname)
}) })
r.Run(":8080") router.Run(":8080")
} }
``` ```