-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat(core/handlers): improve handlers registration DevX #22007
Conversation
📝 Walkthrough📝 WalkthroughWalkthroughThe pull request introduces significant changes to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yml ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
🔇 Additional comments (1)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
@testinginprod your pull request is missing a changelog! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
core/appmodule/v2/handlers.go (1)
165-185
: Approve updates to RegisterMsgHandler functionThe changes to the
RegisterMsgHandler
function significantly improve its flexibility and type safety:
- The function signature now uses more generic type parameters, allowing for greater flexibility in message handling.
- The implementation leverages the new
Handler
struct, which aligns well with the earlier changes in the file.- The addition of
MakeMsg
andMakeMsgResp
functions enables reflection-free instantiation of request and response types.These improvements align perfectly with the PR objective of enhancing the handlers registration developer experience and removing the need for reflection in gRPC and REST handling.
Consider adding a brief comment explaining the purpose of the
PReq
andPResp
type parameters for improved code readability. For example:// PReq and PResp are protobuf-generated types that implement the GenericMsg interface func RegisterMsgHandler[Req, Resp any, PReq transaction.GenericMsg[Req], PResp transaction.GenericMsg[Resp]]( // ... rest of the function )
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
📒 Files selected for processing (2)
- core/appmodule/v2/handlers.go (5 hunks)
- core/transaction/transaction.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
core/appmodule/v2/handlers.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.core/transaction/transaction.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
🔇 Additional comments (9)
core/transaction/transaction.go (3)
13-19
: Excellent addition of theGenericMsg[T any]
interfaceThe new
GenericMsg[T any]
interface is a well-designed and valuable addition to the package. It effectively leverages Go's generics to provide flexibility in handling both pointer and non-pointer versions of messages that implement theMsg
interface. This enhancement aligns well with modern Go practices and improves type safety.The clear and concise documentation explains the purpose and usage of the interface, which is crucial for maintainability and ease of use for other developers.
13-19
: Seamless integration with existing codeThe introduction of the
GenericMsg[T any]
interface is a non-breaking change that enhances the package's capabilities without affecting existing code. It complements theMsg
interface nicely, providing additional flexibility for users who need to work with non-pointer versions of messages in generic contexts.This addition demonstrates thoughtful design that anticipates future needs while maintaining backward compatibility.
Line range hint
1-19
: Overall excellent code quality and structureThe file
core/transaction/transaction.go
maintains high code quality and clear structure. The newGenericMsg[T any]
interface is well-integrated with the existing code, enhancing the package's functionality without disrupting its organization.The code consistently adheres to the Uber Go Style Guide, with clear naming conventions, appropriate documentation, and logical grouping of related elements. This approach ensures that the file remains readable and maintainable as it evolves.
core/appmodule/v2/handlers.go (6)
113-122
: Approve addition of Handler structThe new
Handler
struct is a well-designed addition that encapsulates all necessary information for message handling. It includes:
Func
: The actual handler function.MakeMsg
: A function to instantiate the request message type.MakeMsgResp
: A function to instantiate the response message type.This structure allows for more flexible and type-safe message handling, enabling runtime type instantiation which can be particularly useful for reflection-free operations. This change aligns well with the PR objective of improving the handlers registration developer experience.
Line range hint
1-185
: Summary of changes in core/appmodule/v2/handlers.goThe modifications in this file significantly enhance the message handling system:
- Improved naming conventions for better clarity (e.g.,
HandlerFunc
,RegisterPreMsgHandler
).- Introduction of a new
Handler
struct that encapsulates all necessary information for message handling.- Updated
RegisterMsgHandler
function with more generic type parameters and reflection-free message instantiation.These changes align perfectly with the PR objectives of improving the handlers registration developer experience and removing the need for reflection in gRPC and REST handling. The code is now more consistent, flexible, and type-safe.
22-24
: Approve renaming of RegisterPreHandler to RegisterPreMsgHandlerThe renaming of
RegisterPreHandler
toRegisterPreMsgHandler
improves clarity by explicitly indicating that this function registers a pre-message handler. This change enhances code consistency and readability.To ensure this change doesn't introduce any issues, please run the following command to check for any remaining references to the old
RegisterPreHandler
function:#!/bin/bash # Search for any remaining references to the old RegisterPreHandler function rg --type go 'RegisterPreHandler\('
25-27
: Approve renaming of RegisterGlobalPreHandler to RegisterGlobalPreMsgHandlerThe renaming of
RegisterGlobalPreHandler
toRegisterGlobalPreMsgHandler
improves clarity by explicitly indicating that this function registers a global pre-message handler. This change enhances code consistency and readability.To ensure this change doesn't introduce any issues, please run the following command to check for any remaining references to the old
RegisterGlobalPreHandler
function:#!/bin/bash # Search for any remaining references to the old RegisterGlobalPreHandler function rg --type go 'RegisterGlobalPreHandler\('
67-69
: Approve renaming of RegisterPostHandler to RegisterPostMsgHandlerThe renaming of
RegisterPostHandler
toRegisterPostMsgHandler
improves clarity by explicitly indicating that this function registers a post-message handler. This change enhances code consistency and readability.To ensure this change doesn't introduce any issues, please run the following command to check for any remaining references to the old
RegisterPostHandler
function:#!/bin/bash # Search for any remaining references to the old RegisterPostHandler function rg --type go 'RegisterPostHandler\('
70-71
: Approve renaming of RegisterGlobalPostHandler to RegisterGlobalPostMsgHandlerThe renaming of
RegisterGlobalPostHandler
toRegisterGlobalPostMsgHandler
improves clarity by explicitly indicating that this function registers a global post-message handler. This change enhances code consistency and readability.To ensure this change doesn't introduce any issues, please run the following command to check for any remaining references to the old
RegisterGlobalPostHandler
function:#!/bin/bash # Search for any remaining references to the old RegisterGlobalPostHandler function rg --type go 'RegisterGlobalPostHandler\('
// HandlerFunc handles the state transition of the provided message. | ||
HandlerFunc = func(ctx context.Context, msg transaction.Msg) (msgResp transaction.Msg, err error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Remaining references to Handler
found
The renaming of Handler
to HandlerFunc
in core/appmodule/v2/handlers.go
has introduced multiple remaining references to the old Handler
type across the codebase. Please ensure that all instances are reviewed and updated accordingly to maintain consistency and prevent potential issues.
🔗 Analysis chain
Approve renaming of Handler to HandlerFunc
The renaming of Handler
to HandlerFunc
improves clarity and aligns with Go naming conventions for function types. This change enhances code readability.
To ensure this change doesn't introduce any issues, please run the following command to check for any remaining references to the old Handler
type:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for any remaining references to the old Handler type
rg --type go 'type.*Handler.*=.*func\(ctx context\.Context, msg transaction\.Msg\).*\(transaction\.Msg, error\)'
Length of output: 138
Script:
#!/bin/bash
# Corrected script to search for any remaining references to the old Handler type
rg --type go "type\s+Handler\s*=\s*func\(ctx\s+context\.Context,\s+msg\s+transaction\.Msg\)\s+\(transaction\.Msg,\s+error\)"
Length of output: 126
Script:
#!/bin/bash
# Search for any remaining references to the old Handler type across the codebase
rg --type go '\bHandler\b'
Length of output: 56529
Description
This PR removes the need to provide the message name when registering a handler.
It allows the runtime implementer to define its custom logic to extract messages names from the router.
It will also streamline gRPC handling and Rest handling by not requiring us to use reflection.
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit
GenericMsg
, for enhanced flexibility in message handling.go.mod
file for improved functionality and performance.