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

rpc: allow aliasing methods #3615

Closed
gopherbot opened this issue May 12, 2012 · 8 comments
Closed

rpc: allow aliasing methods #3615

gopherbot opened this issue May 12, 2012 · 8 comments

Comments

@gopherbot
Copy link
Contributor

by damoxc:

I'm currently attempting to implement an existing API using the built-in go rpc package
and stumbled at not being able to keep the same method names as before they were in the
form:

core.hello_world

and as far as I can tell it's only possible to have with the the go rpc package:

core.HelloWorld

The attached patch adds support to method aliasing to the rpc server in a very naive and
simple way. Feel free to ignore this completely!
@gopherbot
Copy link
Contributor Author

Comment 1 by damoxc:

Forgot the patch.

Attachments:

  1. rpc_server.diff (1185 bytes)

@gopherbot
Copy link
Contributor Author

Comment 2 by robpike:

Can you please explain better why you need this? The aliases in your example are not
exported names, so it seems to me you're solving this in the wrong place.

@robpike
Copy link
Contributor

robpike commented May 12, 2012

Comment 3:

Can you please explain better why you need this? The aliases in your example are not
exported names, so it seems to me you're solving this in the wrong place.

Status changed to WaitingForReply.

@gopherbot
Copy link
Contributor Author

Comment 4 by damoxc:

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.

@gopherbot
Copy link
Contributor Author

Comment 5 by robpike:

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.

@gopherbot
Copy link
Contributor Author

Comment 6 by damoxc:

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.

@gopherbot
Copy link
Contributor Author

Comment 7 by robpike:

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.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 8:

Using a codec sounds like the right answer.

Status changed to WorkingAsIntended.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants