The jsonrpc package does not support json-rpc over HTTP at the moment. So you cannot use this, sorry.
But the jsonrpc specification is pretty simple, and it's probably pretty easy to write your own jsonrpchttp package (oh, I hope you know a better name).
I was able to successfully call "getinfo" using the following (terrible) code:
package main import ( "encoding/json" "io/ioutil" "log" "net/http" "strings" ) func main() { data, err := json.Marshal(map[string]interface{}{ "method": "getinfo", "id": 1, "params": []interface{}{}, }) if err != nil { log.Fatalf("Marshal: %v", err) } resp, err := http.Post("http://bob: secret@127.0.0.1 :8332", "application/json", strings.NewReader(string(data))) if err != nil { log.Fatalf("Post: %v", err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatalf("ReadAll: %v", err) } result := make(map[string]interface{}) err = json.Unmarshal(body, &result) if err != nil { log.Fatalf("Unmarshal: %v", err) } log.Println(result) }
Perhaps you can clean it up a bit by implementing the rpc.ClientCodec interface (see jsonrpc / client.go for an example). Then you can use the Go rpc package.
source share