Skip to content
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

🐛 bug: make Render bind parameter type any again #3270

Merged
merged 2 commits into from
Jan 2, 2025

Conversation

efectn
Copy link
Member

@efectn efectn commented Jan 2, 2025

Description

bind parameter of Render method has been converted from any to map[string]any by me a long time ago to keep the parameter type-safe. However this change breaks some usecases such as using bind as struct etc. Therefore, let's revert the change.

Example usecase that html/template supports struct types as binding data: https://pkg.go.dev/html/template#example-package,

Fixes #3219

Changes introduced

  • Documentation Update: Detail the updates made to the documentation and links to the changed files.

Type of change

  • Revert a change.

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

@efectn efectn requested a review from a team as a code owner January 2, 2025 07:23
@efectn efectn requested review from gaby, sixcolors and ReneWerner87 and removed request for a team January 2, 2025 07:23
Copy link
Contributor

coderabbitai bot commented Jan 2, 2025

Walkthrough

The pull request introduces a modification to the Render method across multiple files, changing the bind parameter type from Map to any. This change enhances the flexibility of the Render method by allowing it to accept various data types for template rendering. The modification is consistent across the ctx.go, ctx_interface_gen.go, and docs/api/ctx.md files, ensuring a uniform update to the method signature. A new renderExtensions method has been added to handle binding view variables and local values to the rendering context.

Changes

File Change Summary
ctx.go Updated Render method signature from bind Map to bind any; added renderExtensions method for binding context
ctx_interface_gen.go Updated Render method signature in Ctx interface from bind Map to bind any
docs/api/ctx.md Updated documentation to reflect Render method signature change from bind Map to bind any

Assessment against linked issues

Objective Addressed Explanation
Allow any type for render binding parameters [#3219]
Maintain flexibility in template engine binding

Possibly related PRs

Suggested labels

📒 Documentation, v3

Suggested reviewers

  • sixcolors
  • gaby
  • efectn

Poem

🐰 Render, oh render, with type so free
From Map to any, a template's glee
Flexibility dances, no bounds in sight
Code flows like magic, pure delight!
Hop along, coding with might! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@efectn efectn added this to the v3 milestone Jan 2, 2025
Copy link

codecov bot commented Jan 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.02%. Comparing base (d5771a3) to head (ec6375c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3270      +/-   ##
==========================================
- Coverage   84.04%   84.02%   -0.03%     
==========================================
  Files         116      116              
  Lines       11522    11522              
==========================================
- Hits         9684     9681       -3     
- Misses       1407     1409       +2     
- Partials      431      432       +1     
Flag Coverage Δ
unittests 84.02% <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.

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

🧹 Nitpick comments (1)
ctx_interface_gen.go (1)

15-15: Consider fixing the grammar in the docstring.

In the sentence "Ctx represents the Context which hold the HTTP request and response," consider using "holds" instead of "hold" to maintain grammatical consistency.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d5771a3 and ec6375c.

📒 Files selected for processing (3)
  • ctx.go (1 hunks)
  • ctx_interface_gen.go (2 hunks)
  • docs/api/ctx.md (1 hunks)
🔇 Additional comments (3)
ctx_interface_gen.go (1)

265-265: Reversion to an untyped parameter.

Changing the parameter type from Map to any aligns with the PR objective to allow more flexibility for template binding. However, losing type safety may introduce potential runtime errors if the object bound is not suitable for rendering. Ensure that any checks or validations are handled within the rendering logic as needed.

ctx.go (1)

1372-1372: Revert to any for broader binding support.

This change fulfills the intent of reverting the Render method signature to accept any instead of Map. It addresses use cases where struct binding is needed. Consider adding validation or type checks within the method to prevent runtime panics if unexpected binding data is passed.

docs/api/ctx.md (1)

1509-1509: Documentation alignment with reverted signature.

Updating the Render method signature in the docs from Map to any accurately reflects the revert, ensuring consistency between code and documentation.

@ReneWerner87 ReneWerner87 added the v3 label Jan 2, 2025
@ReneWerner87 ReneWerner87 merged commit 5355869 into main Jan 2, 2025
13 of 14 checks passed
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.

🤗 [Question]: V3: ctx.Render not longer accepts types other than fibre.Map
2 participants