Skip to content

Commit

Permalink
add some protobuf rendering examples in README, add some tests and up…
Browse files Browse the repository at this point in the history
…date some annotations
  • Loading branch information
salamer committed Aug 18, 2018
1 parent 5be19bd commit e51d726
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e51d726

Please sign in to comment.