Skip to content

refactor: Rename "ClientNew" Function to "New"#2896

Merged
ReneWerner87 merged 2 commits intomainfrom
refactor-client-new
Mar 7, 2024
Merged

refactor: Rename "ClientNew" Function to "New"#2896
ReneWerner87 merged 2 commits intomainfrom
refactor-client-new

Conversation

@sixcolors
Copy link
Member

@sixcolors sixcolors commented Mar 4, 2024

Description

I have refactored the "ClientNew" function in our gofiber/fiber/v3/client package to follow standard Go naming conventions. This change involves renaming the function to simply "New", as it aligns better with the recommendations for exported function names between packages and maintains consistency with similar functions within our projects.

  1. The refactor follows the Go language's recommendation for function names within a package. By changing the name to "New", we are adhering to these guidelines, making our code more intuitive.
  2. The move to the subpackage already signifies that it is a client-related function. Therefore, there is no need to include the term "Client" within the function name itself, as this information is already conveyed through its location in the package structure.
  3. This change maintains consistency with other similar functions within our projects.

Type of change

Please delete options that are not relevant.

  • Refactor, raneme function.

Checklist

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

  • 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.

Summary by CodeRabbit

  • Refactor
    • Renamed the client initialization function for consistency and updated all related test scenarios to reflect this change.

@sixcolors sixcolors requested a review from a team as a code owner March 4, 2024 15:11
@sixcolors sixcolors requested review from ReneWerner87, efectn and gaby and removed request for a team March 4, 2024 15:11
@sixcolors sixcolors requested review from wangjq4214 and removed request for ReneWerner87, efectn and gaby March 4, 2024 15:11
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 4, 2024

Walkthrough

The recent updates primarily involve a significant renaming from NewClient to New across various files, focusing on the initialization of client objects. This change affects both the core implementation and the associated tests, streamlining the naming convention and potentially simplifying the API for users and developers alike.

Changes

Files Change Summary
client/client.go, client/client_test.go Renamed NewClient to New, updating all references in tests.
client/core_test.go, ..., client/response_test.go Replaced NewClient() with New() in test setups for requests, timeouts, hooks, responses, and configurations.
middleware/proxy/proxy_test.go Updated clientpkg.NewClient() to clientpkg.New(), affecting client initialization and configuration.

"In the land of code and bytes,
A change was made, one night:
From NewClient to New,
A simpler name, it's true.
🐰 CodeRabbit hopped with delight,
As the code became more light.
'Tis a tale of less to type,
And fewer bugs to swipe!"

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>.
    • Generate unit-tests 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c5a809f and 96bc4b0.
Files selected for processing (8)
  • client/client.go (1 hunks)
  • client/client_test.go (55 hunks)
  • client/core_test.go (9 hunks)
  • client/helper_test.go (3 hunks)
  • client/hooks_test.go (36 hunks)
  • client/request_test.go (16 hunks)
  • client/response_test.go (15 hunks)
  • middleware/proxy/proxy_test.go (6 hunks)
Additional comments: 82
client/helper_test.go (3)
  • 95-95: The change from NewClient() to New() aligns with the PR's objective to simplify naming according to Go conventions. This update is correctly applied in the context of creating a client instance for testing.
  • 122-122: Similar to the previous comment, the update from NewClient() to New() is correctly applied here for initializing a client instance in a failure test scenario. This maintains consistency with the PR's objective.
  • 147-147: Again, the transition from NewClient() to New() is observed here in the context of testing client functionality. The change is consistent with the PR's goal and is correctly implemented.
client/core_test.go (9)
  • 85-85: The update from NewClient() to New() is correctly applied in the context of setting up a client for a normal request test. This change is in line with the PR's objectives and enhances readability.
  • 101-101: The change to use New() for client instantiation in a test scenario where the request returns an error is correctly implemented, adhering to the PR's goal of simplifying naming conventions.
  • 118-118: In the context of testing request timeouts, the transition to New() for client creation is correctly applied, maintaining consistency with the refactor's intent.
  • 160-160: The use of New() in setting up a client for testing user request hooks is appropriate and aligns with the PR's objectives of naming simplification.
  • 177-177: Similarly, the update to New() for initializing a client in the context of testing user response hooks is correctly implemented, adhering to the refactor's goals.
  • 194-194: The change to New() for client instantiation in a no-timeout test scenario is correctly applied, consistent with the PR's aim of simplifying naming conventions.
  • 208-208: In the context of testing client timeouts, the transition to New() for client creation is correctly applied, aligning with the refactor's intent.
  • 221-221: The update from NewClient() to New() for initializing a client in a request timeout test scenario is correctly implemented, adhering to the PR's goal of simplifying naming conventions.
  • 235-235: The use of New() in setting up a client for testing request timeout precedence is appropriate and aligns with the PR's objectives of naming simplification.
client/response_test.go (15)
  • 40-40: The transition from NewClient() to New() for client instantiation in a success response test is correctly applied, consistent with the PR's aim of simplifying naming conventions.
  • 57-57: Similarly, the update to New() for initializing a client in a failure response test is correctly implemented, adhering to the refactor's goals.
  • 91-91: The change to New() for client instantiation in a success status code test is correctly applied, aligning with the PR's objectives of naming simplification.
  • 108-108: The update from NewClient() to New() for initializing a client in a failure status code test is correctly implemented, adhering to the PR's goal of simplifying naming conventions.
  • 133-133: The transition to New() for client creation in an HTTP protocol test is correctly applied, consistent with the refactor's intent.
  • 166-166: The use of New() in setting up a client for an HTTPS protocol test is appropriate and aligns with the PR's objectives of naming simplification.
  • 190-190: The change to New() for client instantiation in a header test is correctly applied, aligning with the PR's objectives of naming simplification.
  • 215-215: Similarly, the update to New() for initializing a client in a cookie test is correctly implemented, adhering to the refactor's goals.
  • 253-253: The transition from NewClient() to New() for client instantiation in a raw body test is correctly applied, consistent with the PR's aim of simplifying naming conventions.
  • 270-270: The update to New() for setting up a client in a string body test is correctly implemented, adhering to the refactor's goals.
  • 290-290: The change to New() for client instantiation in a JSON body test is correctly applied, aligning with the PR's objectives of naming simplification.
  • 315-315: Similarly, the update to New() for initializing a client in an XML body test is correctly implemented, adhering to the refactor's goals.
  • 350-350: The transition from NewClient() to New() for client instantiation in a file path save test is correctly applied, consistent with the PR's aim of simplifying naming conventions.
  • 386-386: The update to New() for setting up a client in an io.Writer save test is correctly implemented, adhering to the refactor's goals.
  • 407-407: The change to New() for client instantiation in an error type save test is correctly applied, aligning with the PR's objectives of naming simplification. However, it's worth noting that the test checks for an error when saving to a nil destination, which is a good practice for validating error handling in the API.
client/hooks_test.go (2)
  • 51-51: The change from NewClient() to New() aligns with Go's naming conventions and simplifies the function call within the context of the client package. This modification enhances readability and adheres to the principle of eliminating redundancy in naming.
  • 522-522: The test case for "raw body error" correctly simulates a scenario where the body is set to nil after being initially set, which should trigger an error. This is a good practice for testing error handling paths in the code. However, it's important to ensure that the error handling is consistent across all similar scenarios and that the error messages provided to the user are clear and helpful.
middleware/proxy/proxy_test.go (6)
  • 141-141: The change from clientpkg.NewClient() to clientpkg.New() correctly follows the PR's objective to adhere to Go naming conventions and eliminate redundancy. This instance specifically updates the client initialization for a test involving TLS configuration.
  • 179-179: The replacement of clientpkg.NewClient() with clientpkg.New() here is consistent with the PR's goal. Additionally, setting a timeout and configuring TLS to skip verification are appropriate for this test scenario, which involves forwarding with TLS configuration to HTTP.
  • 244-244: This change aligns with the PR's objectives and correctly updates the client initialization for a test case that forwards requests with a client TLS configuration. The use of clientpkg.New() and setting the TLS configuration are correctly implemented.
  • 599-599: The transition to clientpkg.New() from clientpkg.NewClient() is correctly applied in the context of testing proxy forwarding with a global client. This change is in line with the PR's objectives and maintains consistency across the test suite.
  • 631-631: Using clientpkg.New() here for testing proxy forwarding with a local client is consistent with the PR's objectives. The change is correctly implemented and contributes to the overall goal of simplifying and standardizing function naming within the package.
  • 709-709: The replacement of clientpkg.NewClient() with clientpkg.New() in this test case for domain forwarding is correctly executed. This change adheres to the PR's objectives and ensures that the new naming convention is consistently applied across the test suite.
client/client.go (1)
  • 689-693: The renaming of the ClientNew function to New aligns with Go's naming conventions, enhancing readability and maintainability. This change is straightforward and correctly implemented. However, it's crucial to ensure that all references to this function across the project, especially in test files and documentation, are updated to reflect this change.
client/client_test.go (44)
  • 65-65: The refactor from NewClient to New is correctly applied here, aligning with Go naming conventions for simplicity and readability.
  • 85-85: The change from NewClient to New is correctly applied in the context of adding response hooks. This maintains consistency with the refactor's objectives.
  • 107-107: The refactor from NewClient to New is correctly applied in the test for checking the order of hooks. This change is consistent with the PR's objectives.
  • 133-133: The change from NewClient to New is correctly applied in the context of setting JSON marshal functions. This maintains the refactor's consistency.
  • 147-147: The change from NewClient to New is correctly applied in the context of setting JSON marshal functions with error handling. This maintains the refactor's consistency.
  • 159-159: The change from NewClient to New is correctly applied in the context of setting JSON unmarshal functions. This maintains the refactor's consistency.
  • 170-170: The change from NewClient to New is correctly applied in the context of setting JSON unmarshal functions with error handling. This maintains the refactor's consistency.
  • 181-181: The change from NewClient to New is correctly applied in the context of setting XML marshal functions. This maintains the refactor's consistency.
  • 193-193: The change from NewClient to New is correctly applied in the context of setting XML marshal functions with error handling. This maintains the refactor's consistency.
  • 205-205: The change from NewClient to New is correctly applied in the context of setting XML unmarshal functions. This maintains the refactor's consistency.
  • 216-216: The change from NewClient to New is correctly applied in the context of setting XML unmarshal functions with error handling. This maintains the refactor's consistency.
  • 229-229: The change from NewClient to New is correctly applied in the context of setting the base URL. This maintains the refactor's consistency.
  • 245-245: The change from NewClient to New is correctly applied in the context of handling invalid URLs. This maintains the refactor's consistency.
  • 255-255: The change from NewClient to New is correctly applied in the context of handling unsupported protocols. This maintains the refactor's consistency.
  • 271-271: The change from NewClient to New is correctly applied in the context of concurrency requests. This maintains the refactor's consistency.
  • 323-323: The change from NewClient to New is correctly applied in the context of the client GET request. This maintains the refactor's consistency.
  • 364-364: The change from NewClient to New is correctly applied in the context of the client HEAD request. This maintains the refactor's consistency.
  • 415-415: The change from NewClient to New is correctly applied in the context of the client POST request. This maintains the refactor's consistency.
  • 471-471: The change from NewClient to New is correctly applied in the context of the client PUT request. This maintains the refactor's consistency.
  • 530-530: The change from NewClient to New is correctly applied in the context of the client DELETE request. This maintains the refactor's consistency.
  • 584-584: The change from NewClient to New is correctly applied in the context of the client OPTIONS request. This maintains the refactor's consistency.
  • 639-639: The change from NewClient to New is correctly applied in the context of the client PATCH request. This maintains the refactor's consistency.
  • 691-691: The change from NewClient to New is correctly applied in the context of setting a custom user agent. This maintains the refactor's consistency.
  • 708-708: The change from NewClient to New is correctly applied in the context of adding a header. This maintains the refactor's consistency.
  • 719-719: The change from NewClient to New is correctly applied in the context of setting a header. This maintains the refactor's consistency.
  • 729-729: The change from NewClient to New is correctly applied in the context of adding multiple headers. This maintains the refactor's consistency.
  • 749-749: The change from NewClient to New is correctly applied in the context of setting multiple headers. This maintains the refactor's consistency.
  • 767-767: The change from NewClient to New is correctly applied in the context of setting a header case-insensitively. This maintains the refactor's consistency.
  • 809-809: The change from NewClient to New is correctly applied in the context of setting a cookie. This maintains the refactor's consistency.
  • 819-819: The change from NewClient to New is correctly applied in the context of setting multiple cookies. This maintains the refactor's consistency.
  • 841-841: The change from NewClient to New is correctly applied in the context of setting cookies with a struct. This maintains the refactor's consistency.
  • 852-852: The change from NewClient to New is correctly applied in the context of deleting cookies. This maintains the refactor's consistency.
  • 1169-1169: The change from NewClient to New is correctly applied in the context of setting a path parameter. This maintains the refactor's consistency.
  • 1179-1179: The change from NewClient to New is correctly applied in the context of setting multiple path parameters. This maintains the refactor's consistency.
  • 1201-1201: The change from NewClient to New is correctly applied in the context of setting path parameters with a struct. This maintains the refactor's consistency.
  • 1212-1212: The change from NewClient to New is correctly applied in the context of deleting path parameters. This maintains the refactor's consistency.
  • 1235-1235: The change from NewClient to New is correctly applied in the context of setting a path parameter and making a GET request. This maintains the refactor's consistency.
  • 1266-1266: The change from NewClient to New is correctly applied in the context of setting TLS configuration. This maintains the refactor's consistency.
  • 1299-1299: The change from NewClient to New is correctly applied in the context of setting TLS configuration and handling errors. This maintains the refactor's consistency.
  • 1329-1329: The change from NewClient to New is correctly applied in the context of making a TLS request without setting a TLS configuration explicitly. This maintains the refactor's consistency.
  • 1343-1343: The change from NewClient to New is correctly applied in the context of setting certificates. This maintains the refactor's consistency.
  • 1350-1350: The change from NewClient to New is correctly applied in the context of setting a root certificate from a file. This maintains the refactor's consistency.
  • 1364-1364: The change from NewClient to New is correctly applied in the context of setting a root certificate from a string. This maintains the refactor's consistency.
  • 1371-1371: The change from NewClient to New is correctly applied in the context of creating a new request. This maintains the refactor's consistency.
client/request_test.go (2)
  • 70-70: The change from NewClient() to New() aligns with the PR's objectives and follows Go's naming conventions. Good job on making the code more idiomatic.
  • 649-649: The refactor from NewClient() to New() is consistently applied across various test functions, maintaining the integrity of the test suite while adhering to Go's naming conventions.

@codecov
Copy link

codecov bot commented Mar 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (main@77770a9). Click here to learn what that means.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2896   +/-   ##
=======================================
  Coverage        ?   82.49%           
=======================================
  Files           ?      116           
  Lines           ?     8321           
  Branches        ?        0           
=======================================
  Hits            ?     6864           
  Misses          ?     1110           
  Partials        ?      347           
Flag Coverage Δ
unittests 82.49% <100.00%> (?)

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.

@ReneWerner87 ReneWerner87 added the v3 label Mar 7, 2024
@ReneWerner87 ReneWerner87 added this to the v3 milestone Mar 7, 2024
@ReneWerner87 ReneWerner87 merged commit 3b982aa into main Mar 7, 2024
@efectn efectn deleted the refactor-client-new branch March 7, 2024 18:50
grivera64 pushed a commit to grivera64/fiber that referenced this pull request Mar 16, 2024
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
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.

4 participants