docs(readme): Add the TOML rendering example (#3400)

This commit is contained in:
mstmdev 2022-11-17 22:37:50 +08:00 committed by GitHub
parent 6150c488e7
commit c629689591
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,7 +49,7 @@ Gin is a web framework written in Go (Golang). It features a martini-like API wi
- [Bind Header](#bind-header) - [Bind Header](#bind-header)
- [Bind HTML checkboxes](#bind-html-checkboxes) - [Bind HTML checkboxes](#bind-html-checkboxes)
- [Multipart/Urlencoded binding](#multiparturlencoded-binding) - [Multipart/Urlencoded binding](#multiparturlencoded-binding)
- [XML, JSON, YAML and ProtoBuf rendering](#xml-json-yaml-and-protobuf-rendering) - [XML, JSON, YAML, TOML and ProtoBuf rendering](#xml-json-yaml-toml-and-protobuf-rendering)
- [SecureJSON](#securejson) - [SecureJSON](#securejson)
- [JSONP](#jsonp) - [JSONP](#jsonp)
- [AsciiJSON](#asciijson) - [AsciiJSON](#asciijson)
@ -1114,7 +1114,7 @@ Test it with:
curl -X POST -v --form name=user --form "avatar=@./avatar.png" http://localhost:8080/profile curl -X POST -v --form name=user --form "avatar=@./avatar.png" http://localhost:8080/profile
``` ```
### XML, JSON, YAML and ProtoBuf rendering ### XML, JSON, YAML, TOML and ProtoBuf rendering
```go ```go
func main() { func main() {
@ -1148,6 +1148,10 @@ func main() {
c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK})
}) })
r.GET("/someTOML", func(c *gin.Context) {
c.TOML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK})
})
r.GET("/someProtoBuf", func(c *gin.Context) { r.GET("/someProtoBuf", func(c *gin.Context) {
reps := []int64{int64(1), int64(2)} reps := []int64{int64(1), int64(2)}
label := "test" label := "test"