- 
                Notifications
    
You must be signed in to change notification settings  - Fork 8.5k
 
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
  
            
          
                binding/bson.go
              
                Outdated
          
        
      | @@ -0,0 +1,30 @@ | |||
| // Copyright 2014 Manu Martinez-Almeida. All rights reserved. | |||
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.
// 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.
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.
hi @laurentcau Please update the header.
| 
           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)
| 
           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 | 
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.
The latest version is: v1.17.4
8806731    to
    168c373      
    Compare
  
    | @@ -1,5 +1,9 @@ | |||
| github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= | |||
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.
go mod tidy
          Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@            Coverage Diff             @@
##           master    #4145      +/-   ##
==========================================
- Coverage   99.21%   98.82%   -0.39%     
==========================================
  Files          42       46       +4     
  Lines        3182     3492     +310     
==========================================
+ Hits         3157     3451     +294     
- Misses         17       30      +13     
- Partials        8       11       +3     
 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.  | 
    
5929e27    to
    901533d      
    Compare
  
    
Add bson protocol for body encoding/decoding