-
Notifications
You must be signed in to change notification settings - Fork 17.4k
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
rpc: allow aliasing methods #3615
Labels
Comments
Forgot the patch. Attachments:
|
By alias I mean aliasing the rpc method call, not the actual method. In the previous program (written in Python) it exported methods in the form: type.method_name What I'm trying to achieve is to have the built-in package able to export a compatible API. Using the rpc package, methods are exported in the form: Type.MethodName (least in my tests this is the case) It's possible to achieve type.MethodName by using rpc.RegisterName instead of rpc.Register, however there's nothing you can do (at least as far as I can see) to manipulate MethodName into method_name. So all the patch did was allow you to run, for example: AliasMethod("type", "MethodName", "method_name") that will mean when someone calls type.method_name via the jsonrpc interface it can resolve Type.MethodName. |
Still not sure about this, but here's another question. Surely it needs to go both ways: a Go client needs to send aliased names to a server it doesn't control, while a Go server needs to accept aliased names to resolve calls from a non-Go client. Either case would be necessary if Go does not define the wire protocol, such as with JSON-RPC. |
I believe (from looking at the docs) the client will be okay since it just executes: client.Call("Type.MethodName") so it can adjust accordingly and call either form as it's simply a string. The trouble is server side since it generates the method names (which are only stored as a string in the map) from the exported method on the type, which has to be capitalised due to the language. |
Copying text by rsc@ from the mail thread: One of the strengths of the RPC server is that you don't have to tell it the method names. I don't know that I'd want to change that. If you have an existing RPC system using lower case names, you must not be using gob as the encoding, which means you've implemented a ServerCodec. My suggestion would be to rewrite the method names in the ServerCodec. When you read "hello_world" from the connection, split it on _, make the first letter of each piece upper case, and put them back together. Or just record "X"+name as the method. Being able to implement your own Codecs is very powerful. You should be able to use that to adapt to just about any convention imposed by the other side. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by damoxc:
The text was updated successfully, but these errors were encountered: