-
Notifications
You must be signed in to change notification settings - Fork 24
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(protocol): Add custom request handling #32
base: main
Are you sure you want to change the base?
Conversation
This commit introduces the ability to handle custom requests in the protocol package. A new struct, CustomRequestHandler, has been added which contains a Method and a Func. The Func is a function that takes a context and params and returns an error. The Handler struct now includes a slice of CustomRequestHandlers, and the Handle method has been updated to handle custom requests by unmarshalling the params into the handler's params and then calling the handler's Func. A new method, FindCustomRequestHandler, has been added to the Handler struct. This method takes a method string and returns the corresponding CustomRequestHandler and a boolean indicating whether the handler was found. The server's handle method has also been updated to handle errors from the Handler's Handle method.
The return type of CustomRequestFunc in both protocol_3_16 and protocol_3_17 has been changed from error to (any, error). This allows the function to return a result alongside an error. The Handler's Handle method has been updated to accommodate this change.
|
exit log``` 2024/06/28 23:45:03 jsonrpc2 handler: notification "exit" handling error: server not initialized ``` |
The 'params' field in the CustomRequestHandler struct has been renamed to 'Params' and made public. This change is reflected in the associated methods where 'params' was used. The 'protocol_3_17/custom.go' file has been deleted. The 'FindCustomRequestHandler' method now returns a 'protocol316.CustomRequestHandler' instead of a 'CustomRequestHandler'.
This commit introduces the ability to handle custom requests in the protocol package. A new struct, CustomRequestHandler, has been added which contains a Method and a Func. The Func is a function that takes a context and params and returns an error.
The Handler struct now includes a slice of CustomRequestHandlers, and the Handle method has been updated to handle custom requests by unmarshalling the params into the handler's params and then calling the handler's Func.
A new method, FindCustomRequestHandler, has been added to the Handler struct. This method takes a method string and returns the corresponding CustomRequestHandler and a boolean indicating whether the handler was found.
The server's handle method has also been updated to handle errors from the Handler's Handle method.
Usage example:
then server.TestHandler as below:
Closes #31