-
Notifications
You must be signed in to change notification settings - Fork 8.2k
feat(render): add bson protocol #4145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
78408cb
to
1e84634
Compare
Please rebase the master branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
func (r BSON) Render(w http.ResponseWriter) error { | ||
r.WriteContentType(w) | ||
|
||
bytes, err := bson.Marshal(&r.Data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider marshaling r.Data directly instead of taking its address with '&', unless this pattern is intentional for handling interface values. Using bson.Marshal(r.Data) may avoid potential issues with pointer indirection.
bytes, err := bson.Marshal(&r.Data) | |
bytes, err := bson.Marshal(r.Data) |
Copilot uses AI. Check for mistakes.
Testing fails. |
Error: ./context.go:40:34: undefined: binding.MIMEBSON |
Add bson protocol for body encoding/decoding