Skip to content

🔥 feat: Add support for Msgpack#3565

Merged
ReneWerner87 merged 18 commits intogofiber:mainfrom
hotrungnhan:main
Jul 14, 2025
Merged

🔥 feat: Add support for Msgpack#3565
ReneWerner87 merged 18 commits intogofiber:mainfrom
hotrungnhan:main

Conversation

@hotrungnhan
Copy link
Contributor

Description

  • Adds native MessagePack (MsgPack) support to Fiber for efficient binary serialization.
  • Introduces new binder and context methods for encoding and decoding MsgPack data.
  • Provides a standardized way to handle MsgPack, similar to existing JSON, XML, and CBOR support.
  • Enables applications to use MsgPack for faster performance and smaller payload sizes.

Fixes # (issue)

Changes introduced

List the new features or adjustments introduced in this pull request:

  • Benchmarks: Added comprehensive benchmarks for MsgPack binding operations and context methods to measure performance improvements over JSON serialization.
  • Documentation Update: Updated documentation in /docs/api/bind.md and /docs/api/ctx.md to include MsgPack binding examples and context method usage.
  • Changelog/What's New: Added MsgPack support as a new feature for the upcoming release, including new context methods c.MsgPack() and binder functionality.
  • Migration Guide: No migration required - this is a non-breaking addition that maintains backward compatibility.
  • API Alignment with Express: While Express.js doesn't have native MsgPack support, the implementation follows Fiber's established patterns for serialization methods, maintaining consistency with existing c.JSON(), c.XML(), and c.CBOR() methods.
  • API Longevity: The new APIs follow established Fiber conventions and patterns, ensuring consistency with existing serialization methods and reducing the likelihood of future breaking changes.
  • Examples: Provided comprehensive examples in documentation and test files demonstrating MsgPack binding and context usage patterns.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Enhancement (improvement to existing features and functionality)
  • Documentation update (changes to documentation)
  • Performance improvement (non-breaking change which improves efficiency)
  • Code consistency (non-breaking change which improves code reliability and robustness)

Checklist

Before you submit your pull request, please make sure you meet these requirements:

  • Followed the inspiration of the Express.js framework for new functionalities, making them similar in usage.
  • Conducted a self-review of the code and provided comments for complex or critical parts.
  • Updated the documentation in the /docs/ directory for Fiber's documentation.
  • Added or updated unit tests to validate the effectiveness of the changes or new features.
  • Ensured that new and existing unit tests pass locally with the changes.
  • Verified that any new dependencies are essential and have been agreed upon by the maintainers/community.
  • Aimed for optimal performance with minimal allocations in the new code.
  • Provided benchmarks for the new code to analyze and improve upon.

Commit formatting

Please use emojis in commit messages for an easy way to identify the purpose or intention of a commit. Check out the emoji cheatsheet here: CONTRIBUTING.md

✅ Used emoji in commit message: 🔥 feat: Add support for Msgpack


Technical Implementation Details

Key Changes Made:

New Files Added:

  • binder/msgpack.go - MsgPack binder implementation
  • binder/msgpack_test.go - Comprehensive test suite for MsgPack binding

Core Framework Changes:

  • New Constants: Added MIMEApplicationMsgPack = "application/vnd.msgpack"
  • New Dependencies: Added github.com/shamaton/msgpack/v2 v2.2.3 for MsgPack serialization
  • Updated Dependencies: Upgraded github.com/gofiber/utils/v2 to support MsgPack types

Context API Enhancements:

  • New Method: c.MsgPack(data any, ctype ...string) error for sending MsgPack responses
  • Content Negotiation: Added "msgpack" support to c.Format() method for automatic content type selection

Configuration Options:

  • MsgPackEncoder: Configurable MsgPack encoder (defaults to msgpack.Marshal)
  • MsgPackDecoder: Configurable MsgPack decoder (defaults to msgpack.Unmarshal)

Binder Integration:

  • MsgPackBinding: New binder for parsing MsgPack request bodies
  • Automatic Registration: MsgPack binder is automatically registered in the binder system

Files Modified:

  • app.go - Added MsgPack encoder/decoder configuration
  • bind.go - Added MsgPack binding support
  • bind_test.go - Added comprehensive MsgPack binding tests
  • binder/binder.go - Registered MsgPack binder
  • binder/mapping.go - Updated content type mapping
  • constants.go - Added MsgPack MIME type constant
  • ctx.go - Added MsgPack context method
  • ctx_interface_gen.go - Updated interface generation for MsgPack method
  • ctx_test.go - Added comprehensive MsgPack context tests
  • docs/api/bind.md - Updated binding documentation
  • docs/api/ctx.md - Updated context documentation
  • go.mod & go.sum - Added MsgPack dependency

Performance Benefits:

  • MsgPack provides more compact binary serialization compared to JSON
  • Faster serialization/deserialization for binary data
  • Reduced network payload sizes for API responses
  • Efficient handling of complex data structures

Usage Examples:

Sending MsgPack Response:

app.Get("/msgpack", func(c *fiber.Ctx) error {
    data := map[string]interface{}{
        "message": "Hello, MsgPack!",
        "status": 200,
    }
    return c.MsgPack(data)
})

Binding MsgPack Request:

type User struct {
    Name  string `msgpack:"name"`
    Email string `msgpack:"email"`
}

app.Post("/user", func(c *fiber.Ctx) error {
    var user User
    if err := c.Bind().MsgPack(&user); err != nil {
        return err
    }
    return c.JSON(user)
})

Content Negotiation:

app.Get("/data", func(c *fiber.Ctx) error {
    data := map[string]interface{}{"key": "value"}
    
    return c.Format(data) // Automatically selects format based on Accept header
    // Supports: application/json, application/xml, application/vnd.msgpack, etc.
})

Copilot AI review requested due to automatic review settings July 4, 2025 21:58
@hotrungnhan hotrungnhan requested a review from a team as a code owner July 4, 2025 21:58
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 4, 2025

Walkthrough

This change introduces MessagePack (MsgPack) encoding and decoding support throughout the Fiber web framework. It adds MsgPack binder logic, context methods for MsgPack serialization, configuration options for custom MsgPack encoders/decoders, new MIME type constants, and comprehensive tests and documentation for MsgPack handling in both request and response flows.

Changes

File(s) Change Summary
app.go, ctx.go, ctx_interface_gen.go Added MsgPack encoder/decoder config fields; added MsgPack method to context and interface; updated AutoFormat for MsgPack support.
bind.go Added MsgPack method to Bind struct; updated Body method to handle MsgPack content type.
binder/binder.go, binder/msgpack.go Added MsgPack binder pool and MsgPackBinding struct with methods (Name, Bind, Reset).
binder/binder_test.go, binder/msgpack_test.go, bind_test.go, ctx_test.go Added unit and benchmark tests for MsgPack binding and context serialization.
constants.go Added MIME type constant for MsgPack.
docs/api/bind.md, docs/api/ctx.md Extended documentation to cover MsgPack support, usage, and examples.
docs/whats_new.md Documented MsgPack support addition and reformatted benchmark table.
docs/api/fiber.md, docs/guide/advance-format.md Added documentation for MsgPack configuration options and a new guide on advanced MsgPack usage.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant FiberApp
    participant Bind
    participant MsgPackBinding

    Client->>FiberApp: HTTP request (Content-Type: application/vnd.msgpack)
    FiberApp->>Bind: Bind.Body(out)
    Bind->>MsgPackBinding: Bind(body, out)
    MsgPackBinding->>Bind: Decode MsgPack body into struct
    Bind->>FiberApp: Return bound struct
    FiberApp->>Client: HTTP response
Loading
sequenceDiagram
    participant Client
    participant FiberApp
    participant Ctx

    Client->>FiberApp: HTTP request (Accept: application/vnd.msgpack)
    FiberApp->>Ctx: AutoFormat(data)
    Ctx->>Ctx: MsgPack(data)
    Ctx->>Client: HTTP response (Content-Type: application/vnd.msgpack, MsgPack-encoded body)
Loading

Possibly related PRs

Suggested reviewers

  • sixcolors
  • efectn
  • gaby
  • ReneWerner87

Poem

In a warren of code, a rabbit did hack,
Bringing MsgPack to Fiber, now nothing we lack!
With bindings and tests, and docs shining bright,
Serialization is swift, and the bytes are just right.
So hop on, dear devs, let your data unpack—
Now Fiber speaks MsgPack, and there’s no turning back!
🥕


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0272d75 and 2fa71a2.

📒 Files selected for processing (1)
  • ctx_test.go (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • ctx_test.go
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @hotrungnhan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Fiber web framework by introducing native support for MessagePack (MsgPack), a highly efficient binary serialization format. This addition allows applications to leverage MsgPack for both request binding and response generation, providing a standardized and performant alternative to existing JSON, XML, and CBOR functionalities, ultimately leading to smaller payload sizes and faster data processing.

Highlights

  • Core MsgPack Integration: Adds native support for MessagePack (MsgPack) serialization and deserialization within the Fiber framework, enabling efficient binary data handling.
  • New Context Method: Introduces c.MsgPack() for easily sending MsgPack encoded responses, similar to existing c.JSON() and c.XML() methods.
  • New Binder Functionality: Adds c.Bind().MsgPack() to parse incoming MsgPack request bodies, providing a standardized way to handle MsgPack input.
  • Content Negotiation Enhancement: Integrates MsgPack into c.Format() and c.AutoFormat() methods, allowing for automatic content type selection based on the client's Accept headers.
  • Configurable Encoders/Decoders: Allows custom MsgPack encoder and decoder implementations to be configured via App settings, providing flexibility for advanced use cases.
  • Performance Benchmarks & Documentation: Includes new benchmarks to measure MsgPack performance and updates API documentation (/docs/api/bind.md, /docs/api/ctx.md) with clear usage examples.
  • New Dependency: Adds github.com/shamaton/msgpack/v2 as the underlying library for MsgPack serialization and deserialization.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

Adds native MessagePack (MsgPack) support to Fiber for efficient binary serialization, including new binder and context methods, documentation, and benchmarks.

  • Introduces c.MsgPack() and binder support mirroring existing JSON/XML/CBOR APIs
  • Updates documentation and examples in /docs/api/* for MsgPack usage
  • Adds tests and benchmarks for MsgPack encoding/decoding and content negotiation

Reviewed Changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
go.mod Added github.com/shamaton/msgpack/v2 and bumped utils/v2
app.go Initialized default MsgPack encoder/decoder in New
constants.go Added MIMEApplicationMsgPack constant
ctx.go Added MsgPack method and AutoFormat support for MsgPack
ctx_interface_gen.go Extended Ctx interface with MsgPack(...)
bind.go Added Bind.MsgPack and MsgPack branch in Body dispatcher
binder/msgpack.go Implemented MsgPackBinding
binder/mapping.go Registered "msgpack" tag for binder pools
binder/binder.go Created MsgPackBinderPool
binder/msgpack_test.go Added unit tests and benchmarks for MsgPack binder
binder/binder_test.go Included MsgPackBinding in binder pool tests
docs/api/ctx.md Documented MsgPack context methods and AutoFormat examples
docs/api/bind.md Documented MsgPack binding and examples
ctx_test.go Added tests and benchmarks for c.MsgPack and AutoFormat
bind_test.go Added tests and benchmarks for Bind.MsgPack
Comments suppressed due to low confidence (5)

docs/api/bind.md:23

  • Remove the space between ] and ( in the Markdown link so it reads [MsgPack](#msgpack) to ensure the anchor works correctly.
  - [MsgPack] (#msgpack)

docs/api/bind.md:53

  • The msgpack tag for the Pass field is incorrectly set to "name"; it should be msgpack:"pass" to match the field name.
    Pass string `json:"pass" xml:"pass" form:"pass" msgpack:"name"`

docs/api/ctx.md:1834

  • The example comment shows application/json but c.MsgPack should set application/vnd.msgpack by default.
  // => Content-Type: application/json

bind.go:244

  • [nitpick] Consider updating the comment to clarify that MsgPack binds the request body bytes as MsgPack, not a string: e.g. // MsgPack binds a MsgPack-encoded request body into the struct.
// MsgPack binds the body string into the struct.

go.mod:7

  • The utils/v2 version contains an extra .0 in the pre-release identifier; please verify the intended module version string.
	github.com/gofiber/utils/v2 v2.0.0-beta.9.0.20250704191817-dad0ed942ea6

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces native MessagePack support to Fiber, which is a great addition for performance-critical applications. The implementation follows existing framework patterns well. My review focuses on improving the correctness of the new tests and fixing some minor issues in the documentation to ensure everything is clear and accurate.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (2)
docs/api/bind.md (2)

23-23: Fix markdown link syntax.

Remove the extra space before the parenthesis in the MsgPack link.

-  - [MsgPack] (#msgpack)
+  - [MsgPack](#msgpack)

53-53: Fix inconsistent struct tag.

The msgpack struct tag should be "pass" to match the field name and be consistent with other tags.

-    Pass string `json:"pass" xml:"pass" form:"pass" msgpack:"name"`
+    Pass string `json:"pass" xml:"pass" form:"pass" msgpack:"pass"`
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 10e92eb and bc8c232.

⛔ Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (14)
  • app.go (3 hunks)
  • bind.go (2 hunks)
  • bind_test.go (3 hunks)
  • binder/binder.go (1 hunks)
  • binder/binder_test.go (1 hunks)
  • binder/mapping.go (1 hunks)
  • binder/msgpack.go (1 hunks)
  • binder/msgpack_test.go (1 hunks)
  • constants.go (1 hunks)
  • ctx.go (3 hunks)
  • ctx_interface_gen.go (4 hunks)
  • ctx_test.go (5 hunks)
  • docs/api/bind.md (4 hunks)
  • docs/api/ctx.md (4 hunks)
🧰 Additional context used
🧠 Learnings (9)
📓 Common learnings
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Feature request #3224 has been created to add support for square bracket notation and comma-separated values in multipart form data in Fiber, while maintaining binary data transfer capabilities. This would bring parity with the existing form-urlencoded functionality.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Fiber currently supports square bracket notation in form data with 'application/x-www-form-urlencoded' content type, but this feature is not available for multipart form data. The implementation for form-urlencoded is in ctx.go (BodyParser method), while multipart form data handling needs enhancement to support this feature.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
binder/binder.go (4)
Learnt from: sixcolors
PR: gofiber/fiber#3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The `session.Save()` method in the `middleware/session` package returns the `Session` back to `sync.Pool`.
Learnt from: sixcolors
PR: gofiber/fiber#3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: The `session.Save()` method in the `middleware/session` package returns the `Session` back to `sync.Pool`.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/session.go:46-61
Timestamp: 2024-10-02T23:02:12.306Z
Learning: In this codebase, the `sessionPool` only contains `Session` instances, so type assertions without additional checks are acceptable.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/session.go:46-61
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In this codebase, the `sessionPool` only contains `Session` instances, so type assertions without additional checks are acceptable.
app.go (8)
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, `Context()` is being renamed to `RequestCtx()`, and `UserContext()` to `Context()` to improve clarity and align with Go's context conventions.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Fiber currently supports square bracket notation in form data with 'application/x-www-form-urlencoded' content type, but this feature is not available for multipart form data. The implementation for form-urlencoded is in ctx.go (BodyParser method), while multipart form data handling needs enhancement to support this feature.
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the `middleware/adaptor/adaptor.go` file of the Fiber framework, when updating context handling, replacing `c.Context()` with `c.RequestCtx()` is appropriate to access the `fasthttp.RequestCtx`.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-07-26T21:00:12.902Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
docs/api/bind.md (1)
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Fiber currently supports square bracket notation in form data with 'application/x-www-form-urlencoded' content type, but this feature is not available for multipart form data. The implementation for form-urlencoded is in ctx.go (BodyParser method), while multipart form data handling needs enhancement to support this feature.
bind_test.go (1)
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
ctx_interface_gen.go (4)
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, `Context()` is being renamed to `RequestCtx()`, and `UserContext()` to `Context()` to improve clarity and align with Go's context conventions.
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the `middleware/adaptor/adaptor.go` file of the Fiber framework, when updating context handling, replacing `c.Context()` with `c.RequestCtx()` is appropriate to access the `fasthttp.RequestCtx`.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.
ctx.go (2)
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the `middleware/adaptor/adaptor.go` file of the Fiber framework, when updating context handling, replacing `c.Context()` with `c.RequestCtx()` is appropriate to access the `fasthttp.RequestCtx`.
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, `Context()` is being renamed to `RequestCtx()`, and `UserContext()` to `Context()` to improve clarity and align with Go's context conventions.
docs/api/ctx.md (6)
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, `Context()` is being renamed to `RequestCtx()`, and `UserContext()` to `Context()` to improve clarity and align with Go's context conventions.
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the `middleware/adaptor/adaptor.go` file of the Fiber framework, when updating context handling, replacing `c.Context()` with `c.RequestCtx()` is appropriate to access the `fasthttp.RequestCtx`.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Fiber currently supports square bracket notation in form data with 'application/x-www-form-urlencoded' content type, but this feature is not available for multipart form data. The implementation for form-urlencoded is in ctx.go (BodyParser method), while multipart form data handling needs enhancement to support this feature.
ctx_test.go (14)

undefined

<retrieved_learning>
Learnt from: gaby
PR: #3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, Context() is being renamed to RequestCtx(), and UserContext() to Context() to improve clarity and align with Go's context conventions.
</retrieved_learning>

<retrieved_learning>
Learnt from: ReneWerner87
PR: #3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the Test method in app.go.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-07-26T21:00:12.902Z
Learning: The project uses the testify/assert package for assertions in unit tests.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The project uses the testify/assert package for assertions in unit tests.
</retrieved_learning>

<retrieved_learning>
Learnt from: gaby
PR: #3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the middleware/adaptor/adaptor.go file of the Fiber framework, when updating context handling, replacing c.Context() with c.RequestCtx() is appropriate to access the fasthttp.RequestCtx.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
</retrieved_learning>

<retrieved_learning>
Learnt from: efectn
PR: #3162
File: hooks_test.go:228-228
Timestamp: 2024-12-13T08:14:22.851Z
Learning: In Go test files, prefer using the require methods from the testify package for assertions instead of manual comparisons and calls to t.Fatal or t.Fatalf.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-09-25T16:18:34.719Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
</retrieved_learning>

<retrieved_learning>
Learnt from: efectn
PR: #3162
File: app_test.go:893-895
Timestamp: 2024-11-29T12:37:27.581Z
Learning: In the Test_App_ShutdownWithContext function in app_test.go, the clientDone channel is used to synchronize the client's request completion before proceeding, eliminating the need for additional time.Sleep calls.
</retrieved_learning>

<retrieved_learning>
Learnt from: gaby
PR: #3170
File: ctx_test.go:1721-1724
Timestamp: 2024-10-16T12:12:30.506Z
Learning: In the Go unit tests in ctx_test.go, it is acceptable to use invalid CIDR notation such as "0.0.0.1/31junk" for testing purposes.
</retrieved_learning>

🧬 Code Graph Analysis (3)
binder/binder.go (1)
binder/msgpack.go (2)
  • MsgPackBinding (6-8)
  • MsgPackBinding (11-13)
binder/binder_test.go (2)
binder/binder.go (2)
  • GetFromThePool (76-83)
  • MsgPackBinderPool (68-74)
binder/msgpack.go (2)
  • MsgPackBinding (6-8)
  • MsgPackBinding (11-13)
ctx.go (1)
constants.go (1)
  • MIMEApplicationMsgPack (30-30)
🔇 Additional comments (30)
binder/mapping.go (2)

37-37: LGTM: Consistent addition of msgpack tag.

The addition of "msgpack" to the tags array correctly extends parser pool classification for the new MsgPack binding support.


211-228: Resolved: MsgPackBinding Doesn’t Use the Field Cache

After verifying the code, the MsgPack bindings simply invoke the external msgpack.Unmarshal (or utils.MsgPackUnmarshal) and never call into our mapping.getFieldCache or buildFieldInfo logic. There is no risk of a panic or missing cache entry because the MsgPack binder bypasses our field‐caching entirely.

constants.go (1)

30-30: LGTM: Correct MsgPack MIME type constant.

The MIME type constant "application/vnd.msgpack" is correct and follows the established naming convention for MIME type constants.

binder/binder.go (1)

68-74: LGTM: Consistent MsgPack binder pool implementation.

The sync.Pool follows the established pattern for other binder pools. The nil initialization for MsgPackDecoder is appropriate, as it should be configured from the app's MsgPack decoder setting before use.

binder/binder_test.go (1)

32-32: LGTM: Appropriate test coverage for MsgPack binder pool.

The test correctly verifies that MsgPackBinding can be retrieved from MsgPackBinderPool, maintaining consistency with other binder pool tests.

app.go (3)

31-31: LGTM: Appropriate MsgPack library import.

Using github.com/shamaton/msgpack/v2 is a well-established and maintained MessagePack library for Go.


324-336: LGTM: Consistent config field addition for MsgPack support.

The MsgPackEncoder and MsgPackDecoder fields follow the exact same pattern as existing JSON, CBOR, and XML encoder/decoder fields, ensuring API consistency.


606-611: LGTM: Proper default initialization for MsgPack codecs.

The initialization logic correctly sets default MsgPack marshal/unmarshal functions when not explicitly configured, following the same pattern as other serialization formats.

bind.go (2)

244-260: LGTM! MsgPack method follows established patterns.

The implementation correctly follows the same pattern as other binding methods (JSON, CBOR, XML) with proper resource management using sync.Pool, consistent error handling, and struct validation.


284-285: LGTM! Content-type dispatch correctly integrated.

The MsgPack case is properly added to the Body method's content-type switch statement, maintaining consistency with existing dispatching logic.

binder/msgpack.go (1)

1-24: LGTM! Clean MsgPack binder implementation.

The MsgPackBinding struct correctly implements the binding interface with proper method signatures and follows the established pattern used by other binders in the framework.

ctx.go (3)

561-561: LGTM! MsgPack correctly integrated into content negotiation.

The addition of "msgpack" to the AutoFormat accepts list properly enables content negotiation for MessagePack responses.


581-582: LGTM! Proper dispatch to MsgPack serialization.

The msgpack case correctly calls the new MsgPack method, maintaining consistency with the AutoFormat switch pattern.


915-931: LGTM! MsgPack method follows established serialization patterns.

The implementation correctly mirrors the JSON and CBOR methods with proper encoder usage, content-type header setting, and error handling. The method signature and behavior are consistent with other serialization methods.

docs/api/bind.md (2)

197-231: LGTM! Comprehensive MsgPack documentation.

The new MsgPack binding section provides clear explanations, proper code examples, and practical curl commands for testing. The documentation follows the established pattern used for other binding methods.


44-44: LGTM! Well-integrated MsgPack content type support.

The MsgPack content type and struct tag are properly documented in the table, and the curl example demonstrates correct usage of the binary MessagePack format.

Also applies to: 76-77

bind_test.go (3)

882-883: LGTM! Struct tags follow established patterns.

The addition of msgpack struct tags is consistent with existing serialization formats and uses appropriate field names.


942-944: LGTM! New MsgPack test case follows established patterns.

The test correctly uses the MsgPack MIME type and appears to use valid MsgPack-encoded data for testing body binding.


1144-1167: LGTM! New MsgPack benchmark is well-implemented.

The benchmark correctly uses MsgPack content type with MsgPack-encoded data and follows established benchmark patterns. The implementation is consistent and accurate.

docs/api/ctx.md (2)

1452-1452: LGTM! MsgPack added to supported content types.

The addition of application/vnd.msgpack to the AutoFormat supported content types is consistent with the new MsgPack functionality.


1482-1484: LGTM! Good example for MsgPack content negotiation.

The example demonstrates proper usage of AutoFormat with MsgPack Accept headers.

ctx_interface_gen.go (3)

187-191: LGTM! MsgPack method properly integrated into interface.

The method signature is consistent with other serialization methods (JSON, CBOR) and follows the established pattern with optional content-type parameter.


57-60: LGTM! Enhanced documentation for context methods.

The expanded comments provide valuable clarification about the no-op behavior of these methods due to fasthttp limitations, with proper reference to the GitHub issue for context.

Also applies to: 67-68, 83-88


329-332: LGTM! Improved Subdomains method documentation.

The enhanced documentation clearly explains the offset behavior and return conditions.

ctx_test.go (6)

1068-1081: LGTM! Benchmark test case for MsgPack content negotiation.

The new benchmark test case properly tests the content negotiation behavior when "msgpack" is requested but not available in the offers. The expectation of no error suggests proper fallback handling.


1104-1108: LGTM! AutoFormat test follows established patterns.

The MsgPack test case correctly follows the same pattern as other AutoFormat tests, converting the response body to string for comparison.


1159-1172: LGTM! Comprehensive struct serialization test for MsgPack.

The test properly verifies that AutoFormat correctly serializes structured data to MessagePack binary format. The expected byte array appears to be a valid MessagePack representation of the test data.


1230-1245: LGTM! Dedicated MsgPack AutoFormat benchmark.

The benchmark follows the established pattern of other AutoFormat benchmarks and provides proper performance measurement for MsgPack serialization.


3744-3823: LGTM! Comprehensive MsgPack method testing.

This test provides excellent coverage of the MsgPack functionality:

  • ✅ Complex number handling (different from JSON behavior)
  • ✅ Basic and custom content type support
  • ✅ Various data types with correct binary expectations
  • ✅ Custom encoder configuration testing
  • ✅ Follows established patterns from JSON/CBOR tests

The binary output expectations appear to be valid MessagePack encodings.


3802-3823: LGTM! Well-structured MsgPack performance benchmark.

The benchmark follows the established pattern of other serialization method benchmarks and provides proper performance measurement with result verification.

@gaby gaby added the v3 label Jul 4, 2025
@gaby gaby added this to v3 Jul 4, 2025
@gaby gaby added this to the v3 milestone Jul 4, 2025
@gaby gaby moved this to In Progress in v3 Jul 4, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
bind_test.go (1)

1131-1131: Fix content type inconsistency in JSON benchmark.

The benchmark sets MsgPack content type but uses JSON-marshaled data, which will cause binding failures. The content type should match the data format.

Apply this fix to use the correct content type:

-	c.Request().Header.SetContentType(MIMEApplicationMsgPack)
+	c.Request().Header.SetContentType(MIMEApplicationJSON)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc8c232 and f0c3a63.

⛔ Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (14)
  • app.go (3 hunks)
  • bind.go (2 hunks)
  • bind_test.go (3 hunks)
  • binder/binder.go (1 hunks)
  • binder/binder_test.go (1 hunks)
  • binder/mapping.go (1 hunks)
  • binder/msgpack.go (1 hunks)
  • binder/msgpack_test.go (1 hunks)
  • constants.go (1 hunks)
  • ctx.go (3 hunks)
  • ctx_interface_gen.go (4 hunks)
  • ctx_test.go (5 hunks)
  • docs/api/bind.md (4 hunks)
  • docs/api/ctx.md (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • binder/mapping.go
🚧 Files skipped from review as they are similar to previous changes (11)
  • constants.go
  • binder/binder.go
  • binder/binder_test.go
  • ctx.go
  • app.go
  • bind.go
  • binder/msgpack.go
  • ctx_interface_gen.go
  • docs/api/ctx.md
  • ctx_test.go
  • binder/msgpack_test.go
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Feature request #3224 has been created to add support for square bracket notation and comma-separated values in multipart form data in Fiber, while maintaining binary data transfer capabilities. This would bring parity with the existing form-urlencoded functionality.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Fiber currently supports square bracket notation in form data with 'application/x-www-form-urlencoded' content type, but this feature is not available for multipart form data. The implementation for form-urlencoded is in ctx.go (BodyParser method), while multipart form data handling needs enhancement to support this feature.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
bind_test.go (1)
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
docs/api/bind.md (3)
Learnt from: hcancelik
PR: gofiber/fiber#3036
File: docs/middleware/cache.md:103-103
Timestamp: 2024-10-08T19:06:06.583Z
Learning: There are no hard tabs in the lines 100 to 105 of the `docs/middleware/cache.md` file. Future comments about formatting should accurately reflect the actual content.
Learnt from: hcancelik
PR: gofiber/fiber#3036
File: docs/middleware/cache.md:103-103
Timestamp: 2024-06-15T19:26:06.401Z
Learning: There are no hard tabs in the lines 100 to 105 of the `docs/middleware/cache.md` file. Future comments about formatting should accurately reflect the actual content.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Fiber currently supports square bracket notation in form data with 'application/x-www-form-urlencoded' content type, but this feature is not available for multipart form data. The implementation for form-urlencoded is in ctx.go (BodyParser method), while multipart form data handling needs enhancement to support this feature.
🪛 LanguageTool
docs/api/bind.md

[style] ~203-~203: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...msgpack` struct tags by default. If you want to use other libraries, you may need to up...

(REP_WANT_TO_VB)

🔇 Additional comments (4)
docs/api/bind.md (1)

197-233: LGTM! Comprehensive MsgPack documentation.

The new MsgPack section provides clear documentation with proper examples, signature, and usage instructions. The curl example and library reference are helpful additions.

bind_test.go (3)

882-883: LGTM! Proper msgpack struct tags added.

The msgpack struct tags are correctly added to the Demo struct, maintaining consistency with other binding tag formats.


942-944: LGTM! Correct MsgPack test implementation.

The MsgPack test case properly uses the correct MIME type and a valid MsgPack-encoded byte slice representing {"name":"john"}.


1144-1167: LGTM! Well-implemented MsgPack benchmark.

The new MsgPack benchmark correctly:

  • Uses the proper MsgPack MIME type
  • Provides a valid MsgPack byte slice
  • Follows the established benchmark pattern
  • Tests the intended MsgPack binding functionality

@hotrungnhan hotrungnhan force-pushed the main branch 3 times, most recently from cef7e34 to 3ba0bcc Compare July 4, 2025 22:37
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
ctx_test.go (2)

1109-1113: Fix the incorrect assertion for MsgPack encoded output.

When AutoFormat is called with Accept: application/vnd.msgpack, it should encode the data using MsgPack, not JSON. The expected output should be MsgPack-encoded bytes, not a JSON string.

Apply this diff to fix the test:

	c.Request().Header.Set(HeaderAccept, MIMEApplicationMsgPack)
	err = c.AutoFormat("Hello, World!")
	require.NoError(t, err)
-	require.Equal(t, `"Hello, World!"`, string(c.Response().Body()))
+	msgpackEncoded, err := c.app.config.MsgPackEncoder("Hello, World!")
+	require.NoError(t, err)
+	require.Equal(t, msgpackEncoded, c.Response().Body())

1234-1249: Fix the incorrect assertion for MsgPack encoded output.

The benchmark incorrectly expects JSON-formatted output when MsgPack encoding should be used.

Apply this diff to fix the benchmark:

	var err error
	for b.Loop() {
		err = c.AutoFormat("Hello, World!")
	}
	require.NoError(b, err)
-	require.Equal(b, `"Hello, World!"`, string(c.Response().Body()))
+	msgpackEncoded, err := c.app.config.MsgPackEncoder("Hello, World!")
+	require.NoError(b, err)
+	require.Equal(b, msgpackEncoded, c.Response().Body())
🧹 Nitpick comments (2)
docs/api/bind.md (2)

44-44: Mention the commonly-used application/msgpack MIME type as well.

Several clients (e.g. msgpack-cli, postman) emit application/msgpack rather than application/vnd.msgpack. Since the implementation already accepts both values, documenting the second variant prevents confusion.

-| `application/vnd.msgpack`           | `msgpack`  |
+| `application/vnd.msgpack`, `application/msgpack` | `msgpack` |

201-203: Tweak wording to avoid repetition.

-If you want to use other libraries, you may need to update the struct tags accordingly.
+When using another MsgPack library, adjust the struct tags if required.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0c3a63 and 3ba0bcc.

⛔ Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (14)
  • app.go (3 hunks)
  • bind.go (2 hunks)
  • bind_test.go (4 hunks)
  • binder/binder.go (1 hunks)
  • binder/binder_test.go (1 hunks)
  • binder/mapping.go (1 hunks)
  • binder/msgpack.go (1 hunks)
  • binder/msgpack_test.go (1 hunks)
  • constants.go (1 hunks)
  • ctx.go (3 hunks)
  • ctx_interface_gen.go (4 hunks)
  • ctx_test.go (6 hunks)
  • docs/api/bind.md (4 hunks)
  • docs/api/ctx.md (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • constants.go
🚧 Files skipped from review as they are similar to previous changes (11)
  • binder/mapping.go
  • binder/binder.go
  • binder/binder_test.go
  • ctx.go
  • app.go
  • bind.go
  • binder/msgpack.go
  • ctx_interface_gen.go
  • binder/msgpack_test.go
  • docs/api/ctx.md
  • bind_test.go
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Feature request #3224 has been created to add support for square bracket notation and comma-separated values in multipart form data in Fiber, while maintaining binary data transfer capabilities. This would bring parity with the existing form-urlencoded functionality.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Fiber currently supports square bracket notation in form data with 'application/x-www-form-urlencoded' content type, but this feature is not available for multipart form data. The implementation for form-urlencoded is in ctx.go (BodyParser method), while multipart form data handling needs enhancement to support this feature.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
ctx_test.go (17)

undefined

<retrieved_learning>
Learnt from: ReneWerner87
PR: #3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the Test method in app.go.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-07-26T21:00:12.902Z
Learning: The project uses the testify/assert package for assertions in unit tests.
</retrieved_learning>

<retrieved_learning>
Learnt from: gaby
PR: #3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, Context() is being renamed to RequestCtx(), and UserContext() to Context() to improve clarity and align with Go's context conventions.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The project uses the testify/assert package for assertions in unit tests.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
</retrieved_learning>

<retrieved_learning>
Learnt from: gaby
PR: #3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the middleware/adaptor/adaptor.go file of the Fiber framework, when updating context handling, replacing c.Context() with c.RequestCtx() is appropriate to access the fasthttp.RequestCtx.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
</retrieved_learning>

<retrieved_learning>
Learnt from: efectn
PR: #3162
File: hooks_test.go:228-228
Timestamp: 2024-12-13T08:14:22.851Z
Learning: In Go test files, prefer using the require methods from the testify package for assertions instead of manual comparisons and calls to t.Fatal or t.Fatalf.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-09-25T16:18:34.719Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
</retrieved_learning>

<retrieved_learning>
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
</retrieved_learning>

<retrieved_learning>
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Fiber currently supports square bracket notation in form data with 'application/x-www-form-urlencoded' content type, but this feature is not available for multipart form data. The implementation for form-urlencoded is in ctx.go (BodyParser method), while multipart form data handling needs enhancement to support this feature.
</retrieved_learning>

<retrieved_learning>
Learnt from: efectn
PR: #3162
File: app_test.go:893-895
Timestamp: 2024-11-29T12:37:27.581Z
Learning: In the Test_App_ShutdownWithContext function in app_test.go, the clientDone channel is used to synchronize the client's request completion before proceeding, eliminating the need for additional time.Sleep calls.
</retrieved_learning>

<retrieved_learning>
Learnt from: gaby
PR: #3170
File: ctx_test.go:1721-1724
Timestamp: 2024-10-16T12:12:30.506Z
Learning: In the Go unit tests in ctx_test.go, it is acceptable to use invalid CIDR notation such as "0.0.0.1/31junk" for testing purposes.
</retrieved_learning>

docs/api/bind.md (3)
Learnt from: hcancelik
PR: gofiber/fiber#3036
File: docs/middleware/cache.md:103-103
Timestamp: 2024-10-08T19:06:06.583Z
Learning: There are no hard tabs in the lines 100 to 105 of the `docs/middleware/cache.md` file. Future comments about formatting should accurately reflect the actual content.
Learnt from: hcancelik
PR: gofiber/fiber#3036
File: docs/middleware/cache.md:103-103
Timestamp: 2024-06-15T19:26:06.401Z
Learning: There are no hard tabs in the lines 100 to 105 of the `docs/middleware/cache.md` file. Future comments about formatting should accurately reflect the actual content.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Fiber currently supports square bracket notation in form data with 'application/x-www-form-urlencoded' content type, but this feature is not available for multipart form data. The implementation for form-urlencoded is in ctx.go (BodyParser method), while multipart form data handling needs enhancement to support this feature.
🪛 LanguageTool
docs/api/bind.md

[style] ~203-~203: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...msgpack` struct tags by default. If you want to use other libraries, you may need to up...

(REP_WANT_TO_VB)

🔇 Additional comments (6)
docs/api/bind.md (1)

52-53: Struct tag now correct – looks good.

The msgpack:"pass" tag fixes the earlier mismatch and aligns with the other formats.

ctx_test.go (5)

996-1000: LGTM!

The test correctly verifies content negotiation behavior for MsgPack format.


1073-1086: LGTM!

The benchmark correctly measures MsgPack format selection performance.


1164-1176: LGTM!

The test correctly verifies MsgPack encoding of structs with proper byte-level assertions.


3748-3804: LGTM!

Comprehensive test coverage for the MsgPack method, including edge cases and custom encoder support.


3806-3826: LGTM!

The benchmark correctly measures MsgPack encoding performance with proper assertions.

@codecov
Copy link

codecov bot commented Jul 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.95%. Comparing base (77540e2) to head (2fa71a2).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3565      +/-   ##
==========================================
+ Coverage   90.91%   90.95%   +0.03%     
==========================================
  Files         110      111       +1     
  Lines       11067    11115      +48     
==========================================
+ Hits        10062    10110      +48     
  Misses        753      753              
  Partials      252      252              
Flag Coverage Δ
unittests 90.95% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gaby
Copy link
Member

gaby commented Jul 4, 2025

@hotrungnhan Don't forget to update the whats_new.md file in docs/.

@hotrungnhan
Copy link
Contributor Author

@gaby I've update the docs, you guy can review now.

Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, just a small comment.

@ReneWerner87
Copy link
Member

@ksw2000 @gofiber/maintainers @coderabbitai
https://github.com/gofiber/fiber/pull/3565/files#r2192367954
ideas to solve this ?

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 8, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Fetch the specific review comment from the GitHub PR
gh api repos/gofiber/fiber/pulls/3565/comments | jq '.[] | select(.id == 2192367954)'

Length of output: 3359


@ReneWerner87, excellent point about dependency management! Here are several approaches to solve this issue:

Solution Options

1. Interface-based Lazy Loading (Recommended)

// In app.go - no direct imports
type MsgPackMarshal func(v any) ([]byte, error)
type MsgPackUnmarshal func(data []byte, v any) error

type Config struct {
    // Remove direct function assignments, use interfaces
    MsgPackEncoder MsgPackMarshal
    MsgPackDecoder MsgPackUnmarshal
}

func New(config ...Config) *App {
    // Don't set defaults here - only when first used
    if cfg.MsgPackEncoder == nil {
        cfg.MsgPackEncoder = getDefaultMsgPackEncoder() // lazy load
    }
}

// In separate file: msgpack_default.go
func getDefaultMsgPackEncoder() MsgPackMarshal {
    return msgpack.Marshal // import only happens here
}

2. Build Tags Approach

// msgpack_enabled.go
//go:build msgpack

import "github.com/shamaton/msgpack/v2"

// msgpack_disabled.go  
//go:build !msgpack

func init() {
    // Provide stub implementations or return errors
}

3. Registry Pattern (Like Middleware)

// In separate package: fiber/msgpack
func init() {
    fiber.RegisterEncoder("msgpack", msgpack.Marshal)
    fiber.RegisterDecoder("msgpack", msgpack.Unmarshal)
}

// Users import: _ "github.com/gofiber/fiber/v3/msgpack"

4. Runtime Registration

// In app.go
var (
    msgPackEncoder MsgPackMarshal
    msgPackDecoder MsgPackUnmarshal
)

func RegisterMsgPack(encoder MsgPackMarshal, decoder MsgPackUnmarshal) {
    msgPackEncoder = encoder
    msgPackDecoder = decoder
}

// In separate package or user code
import "github.com/shamaton/msgpack/v2"

func init() {
    fiber.RegisterMsgPack(msgpack.Marshal, msgpack.Unmarshal)
}

The Interface-based Lazy Loading approach would be most consistent with Fiber's current architecture while solving the dependency issue. Users who need MsgPack would only pull the dependency when they actually configure or use the feature.

Would you prefer to explore one of these approaches further?

🐰 Hopping toward cleaner dependencies!


🧠 Learnings used
Learnt from: sixcolors
PR: gofiber/fiber#3446
File: docs/middleware/logger.md:44-44
Timestamp: 2025-05-13T00:19:16.407Z
Learning: In documentation files for the Fiber framework, code examples are often partial and don't repeat import statements that were shown in earlier examples, focusing instead on demonstrating specific usage patterns.

Learnt from: mdelapenya
PR: gofiber/fiber#3434
File: app.go:623-636
Timestamp: 2025-05-08T08:14:37.302Z
Learning: In the gofiber/fiber framework, service startup failures should panic rather than allowing the application to continue running with degraded functionality, as this is the agreed-upon design decision.

Learnt from: luk3skyw4lker
PR: gofiber/fiber#3074
File: router_test.go:372-397
Timestamp: 2024-10-12T10:01:44.206Z
Learning: There's no short-term plan to support concurrency on the `RebuildTree` method in the Fiber framework as per luk3skyw4lker.

Learnt from: luk3skyw4lker
PR: gofiber/fiber#3074
File: router_test.go:372-397
Timestamp: 2024-07-15T19:53:36.605Z
Learning: There's no short-term plan to support concurrency on the `RebuildTree` method in the Fiber framework as per luk3skyw4lker.

Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.

Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Feature request #3224 has been created to add support for square bracket notation and comma-separated values in multipart form data in Fiber, while maintaining binary data transfer capabilities. This would bring parity with the existing form-urlencoded functionality.

@hotrungnhan
Copy link
Contributor Author

  • Review in progress

it ready now, do i have to squash commit, or it will does automatically ?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
docs/api/ctx.md (2)

1870-1879: Confirm code-block termination

Ensure the triple-back-tick that closes the go title="Example" block is present before the standalone output comments (Content-Type / hex dump). Missing it will break the remainder of the page.


1890-1892: Output comment formatting

For consistency with JSON / CBOR examples, put the Content-Type and hex dump comments inside the example block or both outside – but not split. Pick one style to avoid confusion.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 166bfa9 and 7c7e998.

⛔ Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (16)
  • app.go (3 hunks)
  • bind.go (2 hunks)
  • bind_test.go (5 hunks)
  • binder/binder.go (1 hunks)
  • binder/binder_test.go (1 hunks)
  • binder/msgpack.go (1 hunks)
  • binder/msgpack_test.go (1 hunks)
  • constants.go (1 hunks)
  • ctx.go (3 hunks)
  • ctx_interface_gen.go (1 hunks)
  • ctx_test.go (8 hunks)
  • docs/api/bind.md (7 hunks)
  • docs/api/ctx.md (4 hunks)
  • docs/api/fiber.md (1 hunks)
  • docs/guide/advance-format.md (1 hunks)
  • docs/whats_new.md (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (15)
  • constants.go
  • docs/api/fiber.md
  • binder/binder_test.go
  • ctx_interface_gen.go
  • binder/binder.go
  • docs/whats_new.md
  • bind.go
  • docs/guide/advance-format.md
  • ctx.go
  • app.go
  • binder/msgpack_test.go
  • docs/api/bind.md
  • bind_test.go
  • binder/msgpack.go
  • ctx_test.go
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ksw2000
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2025-07-08T13:41:20.627Z
Learning: ksw2000 suggests implementing a pluggable encoder/decoder registry system in Fiber instead of hardcoding all encoders in app.config. This would solve dependency management issues by allowing users to opt-in only to the formats they need, keeping JSON and XML as defaults while making CBOR and MsgPack explicit registrations.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Feature request #3224 has been created to add support for square bracket notation and comma-separated values in multipart form data in Fiber, while maintaining binary data transfer capabilities. This would bring parity with the existing form-urlencoded functionality.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Fiber currently supports square bracket notation in form data with 'application/x-www-form-urlencoded' content type, but this feature is not available for multipart form data. The implementation for form-urlencoded is in ctx.go (BodyParser method), while multipart form data handling needs enhancement to support this feature.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
docs/api/ctx.md (12)
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, `Context()` is being renamed to `RequestCtx()`, and `UserContext()` to `Context()` to improve clarity and align with Go's context conventions.
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the `middleware/adaptor/adaptor.go` file of the Fiber framework, when updating context handling, replacing `c.Context()` with `c.RequestCtx()` is appropriate to access the `fasthttp.RequestCtx`.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.
Learnt from: hcancelik
PR: gofiber/fiber#3036
File: docs/middleware/cache.md:103-103
Timestamp: 2024-06-15T19:26:06.401Z
Learning: There are no hard tabs in the lines 100 to 105 of the `docs/middleware/cache.md` file. Future comments about formatting should accurately reflect the actual content.
Learnt from: hcancelik
PR: gofiber/fiber#3036
File: docs/middleware/cache.md:103-103
Timestamp: 2024-10-08T19:06:06.583Z
Learning: There are no hard tabs in the lines 100 to 105 of the `docs/middleware/cache.md` file. Future comments about formatting should accurately reflect the actual content.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/config.go:122-122
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In `DefaultErrorHandler(c *fiber.Ctx, err error)`, since `c` is a pointer to an interface, we need to dereference `*c` when calling interface methods like `SendStatus`.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/config.go:122-122
Timestamp: 2024-09-25T16:18:34.719Z
Learning: In `DefaultErrorHandler(c *fiber.Ctx, err error)`, since `c` is a pointer to an interface, we need to dereference `*c` when calling interface methods like `SendStatus`.
Learnt from: mdelapenya
PR: gofiber/fiber#3434
File: docs/api/services.md:39-43
Timestamp: 2025-05-07T13:07:33.899Z
Learning: When documenting Go interface methods in the Fiber project, avoid showing method signatures with the interface type as the receiver (e.g., `func (d *Service) Method()`) since interfaces cannot be used as receivers in Go. Instead, show just the method signature without a receiver or use a placeholder implementation name.
Learnt from: ksw2000
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2025-07-08T13:41:20.627Z
Learning: ksw2000 suggests implementing a pluggable encoder/decoder registry system in Fiber instead of hardcoding all encoders in app.config. This would solve dependency management issues by allowing users to opt-in only to the formats they need, keeping JSON and XML as defaults while making CBOR and MsgPack explicit registrations.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Fiber currently supports square bracket notation in form data with 'application/x-www-form-urlencoded' content type, but this feature is not available for multipart form data. The implementation for form-urlencoded is in ctx.go (BodyParser method), while multipart form data handling needs enhancement to support this feature.
🪛 LanguageTool
docs/api/ctx.md

[grammar] ~1845-~1845: Ensure spelling is correct
Context: ...ack A Replacement for JSON to effiently transfer data between microservices or ...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🔇 Additional comments (4)
docs/api/ctx.md (4)

1368-1374: Table re-flow looks good

The new column descriptions align correctly with Docusaurus’ pipe-table syntax; no rendering issues spotted.


1474-1477: 👍 Added MIME type to AutoFormat list

application/vnd.msgpack is now advertised alongside the existing formats – nice catch.


1506-1509: Hex dump very likely truncated

The MsgPack bytes end abruptly at … 64 6f 65 without closing the map. Earlier feedback flagged the same issue.
Please regenerate the dump or replace it with an ellipsis.

-// => 82 a4 6e 61 6d 65 a4 6a 6f 68 6e a4 70 61 73 73 a3 64 6f 65
+// => 82 A4 6E 61 6D 65 A4 6A 6F 68 6E A4 70 61 73 73 A3 64 6F 65 14
+//           ↑ complete sequence (or add “…” if space is a concern)

1853-1856: Capitalisation of function receiver

All other signatures use (c fiber.Ctx). Current text has (c fiber.Ctx) – good. No change needed.

@ReneWerner87
Copy link
Member

Squash is done automatically

@hotrungnhan
Copy link
Contributor Author

hotrungnhan commented Jul 13, 2025

@ReneWerner87 can you approve the pipeline once again ?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
binder/msgpack_test.go (2)

70-70: Fix incorrect benchmark loop syntax.

The b.Loop() method doesn't exist in Go's testing package.

Apply this diff to fix the benchmark loop:

-	for b.Loop() {
+	for i := 0; i < b.N; i++ {

80-86: Remove assertions from benchmark for accurate performance measurement.

Assertions inside the benchmark loop can affect performance measurements and should be moved outside the loop.

Consider moving these assertions outside the benchmark loop:

 	var user User
 	var err error
+	
+	// Pre-validate the benchmark will work correctly
+	testUser := User{}
+	testErr := binder.Bind([]byte{
+		0x83, 0xa4, 0x6e, 0x61, 0x6d, 0x65, 0xa4, 0x6a, 0x6f, 0x68, 0x6e, 0xa3, 0x61, 0x67, 0x65, 0x2a,
+		0xa5, 0x70, 0x6f, 0x73, 0x74, 0x73, 0x93, 0xa5, 0x70, 0x6f, 0x73, 0x74, 0x31, 0xa5, 0x70, 0x6f,
+		0x73, 0x74, 0x32, 0xa5, 0x70, 0x6f, 0x73, 0x74, 0x33,
+	}, &testUser)
+	require.NoError(b, testErr)
+	
 	for i := 0; i < b.N; i++ {
 		err = binder.Bind([]byte{
 			0x83, 0xa4, 0x6e, 0x61, 0x6d, 0x65, 0xa4, 0x6a, 0x6f, 0x68, 0x6e, 0xa3, 0x61, 0x67, 0x65, 0x2a,
 			0xa5, 0x70, 0x6f, 0x73, 0x74, 0x73, 0x93, 0xa5, 0x70, 0x6f, 0x73, 0x74, 0x31, 0xa5, 0x70, 0x6f,
 			0x73, 0x74, 0x32, 0xa5, 0x70, 0x6f, 0x73, 0x74, 0x33,
 		}, &user)
 	}
-
-	require.NoError(b, err)
-	require.Equal(b, "john", user.Name)
-	require.Equal(b, 42, user.Age)
-	require.Len(b, user.Posts, 3)
-	require.Equal(b, "post1", user.Posts[0])
-	require.Equal(b, "post2", user.Posts[1])
-	require.Equal(b, "post3", user.Posts[2])
+	
+	// Final validation after benchmark
+	require.NoError(b, err)
🧹 Nitpick comments (2)
binder/msgpack_test.go (2)

113-113: Fix grammatical error in panic message validation.

There's a grammatical error in the expected panic message.

Apply this diff to fix the grammar:

-		require.Contains(t, r, "Must explicits setup Msgpack")
+		require.Contains(t, r, "Must explicitly setup Msgpack")

126-126: Fix grammatical error in panic message validation.

There's a grammatical error in the expected panic message (same as line 113).

Apply this diff to fix the grammar:

-		require.Contains(t, r, "Must explicits setup Msgpack")
+		require.Contains(t, r, "Must explicitly setup Msgpack")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 52bc3ff and d32c378.

📒 Files selected for processing (2)
  • bind_test.go (5 hunks)
  • binder/msgpack_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • bind_test.go
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ksw2000
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2025-07-08T13:41:20.627Z
Learning: ksw2000 suggests implementing a pluggable encoder/decoder registry system in Fiber instead of hardcoding all encoders in app.config. This would solve dependency management issues by allowing users to opt-in only to the formats they need, keeping JSON and XML as defaults while making CBOR and MsgPack explicit registrations.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Feature request #3224 has been created to add support for square bracket notation and comma-separated values in multipart form data in Fiber, while maintaining binary data transfer capabilities. This would bring parity with the existing form-urlencoded functionality.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Fiber currently supports square bracket notation in form data with 'application/x-www-form-urlencoded' content type, but this feature is not available for multipart form data. The implementation for form-urlencoded is in ctx.go (BodyParser method), while multipart form data handling needs enhancement to support this feature.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:30:20.597Z
Learning: In Fiber, square bracket notation in form data is currently supported only with 'application/x-www-form-urlencoded' content type, but not with multipart form data. This limitation affects parsing nested structures in multipart form data.
binder/msgpack_test.go (8)
Learnt from: efectn
PR: gofiber/fiber#3162
File: hooks_test.go:228-228
Timestamp: 2024-12-13T08:14:22.851Z
Learning: In Go test files, prefer using the `require` methods from the `testify` package for assertions instead of manual comparisons and calls to `t.Fatal` or `t.Fatalf`.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-07-26T21:00:12.902Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: sixcolors
PR: gofiber/fiber#3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for `Session.Save` already exist in the `middleware/session/session_test.go` file, specifically in the `Test_Session_Save` and `Test_Session_Save_Expiration` functions.
Learnt from: sixcolors
PR: gofiber/fiber#3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for `Session.Save` already exist in the `middleware/session/session_test.go` file, specifically in the `Test_Session_Save` and `Test_Session_Save_Expiration` functions.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
🔇 Additional comments (2)
binder/msgpack_test.go (2)

10-53: Comprehensive test coverage looks good.

The test properly validates MsgPack binding functionality with complex nested structures and verifies the Reset() method behavior.


89-106: Proper panic testing implementation.

The tests correctly verify that the unimplemented MsgPack functions panic as expected when called without proper setup.

@hotrungnhan
Copy link
Contributor Author

@gaby @ReneWerner87 Plz approve one more time, I’ve fixed the benchmark and added some additional documentation.

@ReneWerner87 ReneWerner87 merged commit 8f02e01 into gofiber:main Jul 14, 2025
14 checks passed
@welcome
Copy link

welcome bot commented Jul 14, 2025

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants