Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions docs/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ func main() {

// This handler will add a new router for /user/groups.
// Exact routes are resolved before param routes, regardless of the order they were defined.
// Routes starting with /user/groups are never interpreted as /user/:name/... routes
// Only the exact path /user/groups is matched here. A longer path such as
// /user/groups/admin still matches /user/:name/*action, with name set to "groups".
router.GET("/user/groups", func(c *gin.Context) {
c.String(http.StatusOK, "The available groups are [...]")
})
Expand Down Expand Up @@ -309,7 +310,7 @@ func main() {
```

```sh
ids: map[b:hello a:1234]; names: map[second:tianou first:thinkerou]
ids: map[a:1234 b:hello]; names: map[first:thinkerou second:tianou]
```

### Upload files
Expand Down Expand Up @@ -866,7 +867,7 @@ Also, Gin provides two sets of methods for binding:

- **Type** - Must bind
- **Methods** - `Bind`, `BindJSON`, `BindXML`, `BindQuery`, `BindYAML`, `BindHeader`, `BindTOML`
- **Behavior** - These methods use `MustBindWith` under the hood. If there is a binding error, the request is aborted with `c.AbortWithError(400, err).SetType(ErrorTypeBind)`. This sets the response status code to 400 and the `Content-Type` header is set to `text/plain; charset=utf-8`. Note that if you try to set the response code after this, it will result in a warning `[GIN-debug] [WARNING] Headers were already written. Wanted to override status code 400 with 422`. If you wish to have greater control over the behavior, consider using the `ShouldBind` equivalent method.
- **Behavior** - These methods use `MustBindWith` under the hood. If there is a binding error, the request is aborted with `c.AbortWithError(400, err).SetType(ErrorTypeBind)`. This sets the response status code to 400 and writes the response headers right away, with an empty body and no `Content-Type` header. Note that if you try to set the response code after this, it will result in a warning `[GIN-debug] [WARNING] Headers were already written. Wanted to override status code 400 with 422`. If you wish to have greater control over the behavior, consider using the `ShouldBind` equivalent method.
- **Type** - Should bind
- **Methods** - `ShouldBind`, `ShouldBindJSON`, `ShouldBindXML`, `ShouldBindQuery`, `ShouldBindYAML`, `ShouldBindHeader`, `ShouldBindTOML`,
- **Behavior** - These methods use `ShouldBindWith` under the hood. If there is a binding error, the error is returned and it is the developer's responsibility to handle the request and error appropriately.
Expand Down Expand Up @@ -1797,7 +1798,7 @@ func main() {
}

//callback is x
// Will output : x({\"foo\":\"bar\"})
// Will output : x({"foo":"bar"});
c.JSONP(http.StatusOK, data)
})

Expand Down Expand Up @@ -2519,19 +2520,7 @@ func main() {

if err != nil {
cookie = "NotSet"
// Using http.Cookie struct for more control
c.SetCookieData(&http.Cookie{
Name: "gin_cookie",
Value: "test",
Path: "/",
Domain: "localhost",
MaxAge: 3600,
Secure: false,
HttpOnly: true,
// Additional fields available in http.Cookie
Expires: time.Now().Add(24 * time.Hour),
// Partitioned: true, // Available in newer Go versions
})
c.SetCookie("gin_cookie", "test", 3600, "/", "localhost", false, true)
}

fmt.Printf("Cookie value: %s \n", cookie)
Expand Down
Loading