From a777c1532ae3f45efaaabd7d7b7866a2c294e9f4 Mon Sep 17 00:00:00 2001 From: jarch09 Date: Sat, 10 Sep 2022 15:08:21 -0400 Subject: [PATCH] adding to readme --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8d7b5ec4..fea3f577 100644 --- a/README.md +++ b/README.md @@ -1150,10 +1150,9 @@ func main() { r.GET("/someProtoBuf", func(c *gin.Context) { reps := []int64{int64(1), int64(2)} - label := "test" // The specific definition of protobuf is written in the testdata/protoexample file. data := &protoexample.Test{ - Label: &label, + Label: "test", Reps: reps, } // Note that data becomes binary data in the response @@ -1161,6 +1160,19 @@ func main() { 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 r.Run(":8080") }