<p>Hi, as an example I want to run the method "getdifficulty" on bitcoind and show the result.</p>
<p>What's the cleanest way to use json-rpc over http? (without over complicating things) (and why isn't net/rpc/jsonrpc not working?)</p>
<p>I've already done it using <a href="https://github.com/btcsuite/btcrpcclient" rel="nofollow">btcrpcclient</a> and I also tried <a href="http://stackoverflow.com/questions/8918455/how-to-properly-call-json-rpc-in-go" rel="nofollow">this way</a>.</p>
<p>I'm trying to do it without btcrpcclient because I wanted to know how much overhead that library add. So I'm reinventing the wheel a bit to avoid using such a big library when I'll only need to use a few methods.</p>
<p>With the SO answer, I wanted to clean up the code a bit, to avoid giving the address every time I thought about making a client. but seems like the rpc package already do that kind of client, so I tried to do the same thing but with a custom codec but couldn't really make something that works.</p>
<hr/>**评论:**<br/><br/>Incubuss: <pre><p>I made a really basic JSON RPC over HTTP "library" a while ago to test something I was working on. I said "library" because it's not a library, it doesn't have any tests, and the code probably has some issues, however it demonstrates how easy it is to do it yourself: <a href="https://github.com/JamesMcMinn/json-rpc-http/blob/master/rcp.go" rel="nofollow">https://github.com/JamesMcMinn/json-rpc-http/blob/master/rcp.go</a></p></pre>Simpfally: <pre><p>After posting I actually had some free time to try what I said. So I used a client struct. My code was a bit similar to yours but without the closure. </p>
<p>Finally I removed the struct part and simply did a function to make the request and two functions for the two methods I'm gonna use on bitcoind. More straightforward even if it's less expendable.</p>
<p>I'm gonna do some benchmark now</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传