mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-23 01:57:55 +08:00
add some protobuf rendering examples in README, add some tests and update some annotations
This commit is contained in:
parent
5be19bd95c
commit
e51d726b33
16
README.md
16
README.md
@ -40,7 +40,7 @@ Gin is a web framework written in Go (Golang). It features a martini-like API wi
|
||||
- [Bind Query String or Post Data](#bind-query-string-or-post-data)
|
||||
- [Bind HTML checkboxes](#bind-html-checkboxes)
|
||||
- [Multipart/Urlencoded binding](#multiparturlencoded-binding)
|
||||
- [XML, JSON and YAML rendering](#xml-json-and-yaml-rendering)
|
||||
- [XML, JSON, YAML and ProtoBuf rendering](#xml-json-yaml-and-protobuf-rendering)
|
||||
- [JSONP rendering](#jsonp)
|
||||
- [Serving static files](#serving-static-files)
|
||||
- [Serving data from reader](#serving-data-from-reader)
|
||||
@ -871,7 +871,7 @@ Test it with:
|
||||
$ curl -v --form user=user --form password=password http://localhost:8080/login
|
||||
```
|
||||
|
||||
### XML, JSON and YAML rendering
|
||||
### XML, JSON, YAML and ProtoBuf rendering
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -905,6 +905,18 @@ func main() {
|
||||
c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK})
|
||||
})
|
||||
|
||||
r.GET("/someProtoBuf", func(c *gin.Context) {
|
||||
reps := []int64{int64(1), int64(2)}
|
||||
label := "test"
|
||||
|
||||
// Proto specifically defines the testdata/protoexample file
|
||||
data := &protoexample.Test{
|
||||
Label: &label,
|
||||
Reps: reps,
|
||||
}
|
||||
c.ProtoBuf(http.StatusOK, data)
|
||||
})
|
||||
|
||||
// Listen and serve on 0.0.0.0:8080
|
||||
r.Run(":8080")
|
||||
}
|
||||
|
@ -971,7 +971,7 @@ func TestContextRenderProtoBuf(t *testing.T) {
|
||||
Reps: reps,
|
||||
}
|
||||
|
||||
c.ProtoBuf(201, data)
|
||||
c.ProtoBuf(http.StatusCreated, data)
|
||||
|
||||
protoData, err := proto.Marshal(data)
|
||||
assert.NoError(t, err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user