Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

laurentcau
Copy link

@laurentcau laurentcau commented Jan 22, 2025

Add bson protocol for body encoding/decoding

@laurentcau laurentcau force-pushed the bson branch 3 times, most recently from 78408cb to 1e84634 Compare January 23, 2025 10:02
@laurentcau
Copy link
Author

ping
@manucorporat
@javierprovecho

@appleboy appleboy added this to the v1.11 milestone Feb 12, 2025
@appleboy appleboy requested a review from Copilot May 20, 2025 10:49
@appleboy
Copy link
Member

Please rebase the master branch.

Copy link

@Copilot Copilot AI left a 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.

Copy link

@Copilot Copilot AI left a 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)
Copy link
Preview

Copilot AI May 20, 2025

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.

Suggested change
bytes, err := bson.Marshal(&r.Data)
bytes, err := bson.Marshal(r.Data)

Copilot uses AI. Check for mistakes.

@appleboy appleboy changed the title add bson protocol feat(render): add bson protocol May 20, 2025
@appleboy
Copy link
Member

Testing fails.

@laurentcau
Copy link
Author

laurentcau commented May 21, 2025

Testing fails.

Error: ./context.go:40:34: undefined: binding.MIMEBSON
Error: ./context.go:1272:15: undefined: binding.MIMEBSON
It looks like "ubuntu-latest @ Go 1.23 -tags nomsgpack (pull_request)" doesn't use the right binding/binding.go file because MIMEBSON is defined:
MIMEBSON = "application/bson"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants