mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-17 14:12:16 +08:00
adding to readme
This commit is contained in:
parent
0220b302d7
commit
a777c1532a
16
README.md
16
README.md
@ -1150,10 +1150,9 @@ func main() {
|
|||||||
|
|
||||||
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"
|
|
||||||
// The specific definition of protobuf is written in the testdata/protoexample file.
|
// The specific definition of protobuf is written in the testdata/protoexample file.
|
||||||
data := &protoexample.Test{
|
data := &protoexample.Test{
|
||||||
Label: &label,
|
Label: "test",
|
||||||
Reps: reps,
|
Reps: reps,
|
||||||
}
|
}
|
||||||
// Note that data becomes binary data in the response
|
// Note that data becomes binary data in the response
|
||||||
@ -1161,6 +1160,19 @@ func main() {
|
|||||||
c.ProtoBuf(http.StatusOK, data)
|
c.ProtoBuf(http.StatusOK, data)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
r.GET("/someProtoJSON", func(c *gin.Context) {
|
||||||
|
reps := []int64{int64(1), int64(2)}
|
||||||
|
// The specific definition of protobuf is written in the testdata/protoexample file.
|
||||||
|
data := &protoexample.Test{
|
||||||
|
Label: "test",
|
||||||
|
Reps: reps,
|
||||||
|
}
|
||||||
|
// Note that data becomes JSON data in the response
|
||||||
|
// (But under the hood, this calls protojson.Marshal, which is the correct
|
||||||
|
// way to render protos as JSON)
|
||||||
|
c.ProtoJSON(http.StatusOK, data)
|
||||||
|
})
|
||||||
|
|
||||||
// Listen and serve on 0.0.0.0:8080
|
// Listen and serve on 0.0.0.0:8080
|
||||||
r.Run(":8080")
|
r.Run(":8080")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user