Skip to content

Commit

Permalink
chore: add bind cookie to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcec0de committed Feb 12, 2023
1 parent 48c5617 commit 582a864
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions docs/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [Bind Query String or Post Data](#bind-query-string-or-post-data)
- [Bind Uri](#bind-uri)
- [Bind Header](#bind-header)
- [Bind Cookie](#bind-cookie)
- [Bind HTML checkboxes](#bind-html-checkboxes)
- [Multipart/Urlencoded binding](#multiparturlencoded-binding)
- [XML, JSON, YAML, TOML and ProtoBuf rendering](#xml-json-yaml-toml-and-protobuf-rendering)
Expand Down Expand Up @@ -900,6 +901,45 @@ func main() {
}
```

### Bind Cookie

```go
package main

import (
"fmt"
"net/http"

"github.com/gin-gonic/gin"
)

type testCookie struct {
Rate int `cookie:"Rate"`
Domain string `cookie:"Domain"`
}

func main() {
r := gin.Default()
r.GET("/", func(c *gin.Context) {
h := testCookie{}

if err := c.ShouldBindCookie(&h); err != nil {
c.JSON(http.StatusOK, err)
}

fmt.Printf("%#v\n", h)
c.JSON(http.StatusOK, gin.H{"Rate": h.Rate, "Domain": h.Domain})
})

r.Run()

// client
// curl -H "rate:300" -H "domain:music" 127.0.0.1:8080/
// output
// {"Domain":"music","Rate":300}
}
```

### Bind HTML checkboxes

See the [detail information](https://github.com/gin-gonic/gin/issues/129#issuecomment-124260092)
Expand Down

0 comments on commit 582a864

Please sign in to comment.