-
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
net/rpc/jsonrpc: Missing support for JSON-RPC 2.0 #10929
Comments
I'd like to implement it. I've enough experience with JSON RPC 2.0 (I'm author of several related Perl modules like JSON::RPC2 and Mojolicious::Plugin::JSONRPC2) but this task is going to be my first Go project (and it feels a bit too complicated for the first project). I've checked current interface of net/rpc, and it looks like to support some features of JSON RPC 2.0 we'll need some… hacks. For example, right now I see only way to implement support for "batch" requests:
If there are simpler ways to do this - let me know, please. |
Another issue, which I don't think can be worked around without slight change of net/rpc interface, is support for custom error codes. Spec define error codes, some should be used by RPC engine implementation, others can be returned from user's RPC handler. If net/rpc had use The Only way around I see is serializing both error code and message into returned error's text, and then in codec try to analyse error text and detect is it contain only error message or both error code and message serialized that way. It's ugly, but should work. |
I have resorted to not using the net/rpc because of the same reasons with custom error codes and batching. Instead, I added the RPC code inside the jsonrpc2 package. I'll open source that package in a few days here on Github so you can take a look at it. |
I've implemented jsonrpc2 codec for net/rpc: https://github.com/powerman/rpc-codec
|
Is there any reason this needs to be in the standard library? (See http://golang.org/doc/faq#x_in_std for background on the question.) |
I don't think it should be in the standard library. But when people see JSON-RPC 1.0 support in standard library, and "codecs" support in net/rpc they start looking for 2.0 support for net/rpc… and don't find any. So I think it's worth mentioning in this issue. I decided to implement it as a codec instead of separate rpc-package mostly as educational task - to learn how net/rpc implemented, check is interfaces mentioned in JSON-RPC: a tale of interfaces are flexible enough, and to avoid implementing both protocol and RPC engine in my first project. |
Perhaps we can just update the
Thoughts? |
https://godoc.org/?q=json-rpc+2.0 will works better. 😄 |
It's good enough for me as I don't think JSONRPC2 can be fully supported in an idomatic way without rewriting the net/rpc package. |
Want to send in a change updating the package doc? |
@bradfitz Yes, I'm happy to do that, but do I need to follow the contributor process for it? |
Ping! |
@Dynom https://godoc.org/github.com/powerman/rpc-codec/jsonrpc2 works ok in several production services for about 6 months. I've plans to add more usage examples in doc and probably option to switch it to "loose" mode (less sanity checks just like in net/rpc/jsonrpc to get higher speed). Also I'm considering developing separate module for JSON RPC 2.0 (independent from net/rpc) - this should result in simpler implementation because there will be no needs to work around net/rpc limitations and more features because of same reason (like ability to provide transport-level details - for example client's IP - to called method). |
Excellent work @powerman, I've currently worked around it by simply performing an HTTP request (it was a very trivial and static request to a JSON-RPC 2 server over HTTP). However I need to build several servers and clients that consume JSON-RPC 2 over HTTP, so your work is greatly appreciated. I'll check it out and I'll contribute where I can. |
I've implemented a JSON-RPC 2.0 HTTP handler that also supports batch requests. |
CL https://golang.org/cl/36330 mentions this issue. |
@dwlnetnl Would you mind updating your last comment with the correct URL? The current one seems broken. |
@Dynom I haven't that code not around anymore, sorry. |
Specification is at http://www.jsonrpc.org/specification
The text was updated successfully, but these errors were encountered: