feat(render): add bson protocol#4145
Conversation
78408cb to
1e84634
Compare
binding/bson.go
Outdated
| @@ -0,0 +1,30 @@ | |||
| // Copyright 2014 Manu Martinez-Almeida. All rights reserved. | |||
There was a problem hiding this comment.
// Copyright 2025 Gin Core Team. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
|
Please rebase the master branch. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for BSON encoding/decoding to the project, primarily by introducing new rendering and binding functionality along with corresponding tests.
- Adds BSON render implementation in the render package with associated tests.
- Extends context negotiation logic to support BSON responses.
- Provides BSON binding support in the binding package with tests and updates to go.mod.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| render/render_test.go | Added tests for BSON rendering. |
| render/bson.go | Introduces the BSON render logic for HTTP responses. |
| go.mod | Adds mongo-driver dependency. |
| context_test.go | Includes tests for BSON negotiation. |
| context.go | Adds MIMEBSON constant and BSON response method. |
| binding/bson.go | Implements BSON binding for request bodies. |
| binding/binding_test.go | Extends tests to cover BSON binding. |
| binding/binding.go | Updates binding mapping to include BSON. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for encoding/decoding BSON in the framework by introducing a new render type, updating content negotiation, and wiring BSON binding in the binding package.
- Added BSON render implementation and corresponding tests in render/render_test.go
- Updated context and binding files to include BSON handling for both response rendering and data binding
- Updated go.mod to include the mongo-driver dependency
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| render/render_test.go | Added tests for BSON rendering |
| render/bson.go | Introduced BSON render type and content type writer |
| go.mod | Added mongo-driver dependency |
| context_test.go | Added test for context negotiation with BSON |
| context.go | Extended context with BSON support in Negotiate and helper |
| binding/bson.go | Introduced BSON binding implementation |
| binding/binding.go | Updated default binding to support BSON |
| binding/binding_test.go | Added BSON binding tests |
Comments suppressed due to low confidence (1)
binding/binding_test.go:747
- In the negative test branch for BSON binding, the test uses JSON.Bind instead of the expected BSON binding. Consider using b.Bind(req, &obj) (or BSON.Bind(req, &obj)) to properly test error handling in the BSON binding implementation.
err = JSON.Bind(req, &obj)
|
Testing fails. |
Error: ./context.go:40:34: undefined: binding.MIMEBSON |
27562a7 to
e36d457
Compare
|
@laurentcau Please update the latest code. |
go.mod
Outdated
| github.com/pmezard/go-difflib v1.0.0 // indirect | ||
| github.com/quic-go/qpack v0.5.1 // indirect | ||
| github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
| go.mongodb.org/mongo-driver v1.17.2 // indirect |
8806731 to
168c373
Compare
| @@ -1,5 +1,9 @@ | |||
| github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= | |||
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4145 +/- ##
==========================================
- Coverage 99.21% 99.01% -0.21%
==========================================
Files 42 46 +4
Lines 3182 3038 -144
==========================================
- Hits 3157 3008 -149
- Misses 17 21 +4
- Partials 8 9 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@laurentcau Please help resolve the conflicts. |
|
@laurentcau, sorry, please help to upgrade Go mod files. |
15c2efe to
4132c8a
Compare
|
@laurentcau Please help to resolve the conflicts. |
|
ping @laurentcau |
65f7aad to
ff16cf5
Compare
|
@laurentcau THanks. |

Add bson protocol for body encoding/decoding