<p>Ah... got there myself taking things from multiple sources!</p>
<p>Here's the code snippet:</p>
<pre class="lang-go prettyprint-override"><code>package main

import (
    &quot;fmt&quot;
    &quot;io/ioutil&quot;
    &quot;net/http&quot;
    &quot;strings&quot;
)

func main() {
    testRequest := `{&quot;jsonrpc&quot;: &quot;1.0&quot;, &quot;id&quot;:&quot;&quot;, &quot;method&quot;: &quot;getrpcinfo&quot;, &quot;params&quot;: []}`

    req, _ := http.NewRequest(&quot;POST&quot;, &quot;http://127.0.0.1:8332/&quot;, strings.NewReader(testRequest))
    req.SetBasicAuth(&quot;&quot;, &quot;notmypassword&quot;)
    req.Header.Add(&quot;content-type&quot;, &quot;text/plain;&quot;)

    res, e := http.DefaultClient.Do(req)
    if e != nil {
        fmt.Println(e)
    } else {
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
        fmt.Println(string(body))
    }
}
</code></pre>

CC BY-SA 4.0
2022-05-10T17:53:54.203Z
At lest you could accept your own answer :)
Ron
CC BY-SA 4.0
2021-05-07T12:50:08.887Z
2024-04-03T13:29:29.660Z
2024-04-03T13:29:29.660Z
Nigel Sharp
<p>I've done it previously in C++ and I'm currently learning go/golang</p>
<p>I'd rather do it &quot;from scratch&quot; rather than trust a third party's library</p>
<p>Just a call from golang for a json-rpc call to getrpcinfo would be enough to get me moving!</p>
<p>My search so far has only led to entire libraries and applications</p>

<bitcoin-core><json-rpc><go-lang>
Looking for a tiny go/golang snippet to connect to bitcoin core json rpc
Nigel Sharp
# Looking for a tiny go/golang snippet to connect to bitcoin core json rpc

(Asked by: username_0 on 2021-05-07)

I've done it previously in C++ and I'm currently learning go/golang

I'd rather do it "from scratch" rather than trust a third party's library

Just a call from golang for a json-rpc call to getrpcinfo would be enough to get me moving!

My search so far has only led to entire libraries and applications

**Tags:** bitcoin-core, json-rpc, go-lang


---

## 1 answers

### Answer by username_0 on 2021-05-07. Score: 4 | Accepted answer

Ah... got there myself taking things from multiple sources!
Here's the code snippet:
package main

import (
    "fmt"
    "io/ioutil"
    "net/http"
    "strings"
)

func main() {
    testRequest := `{"jsonrpc": "1.0", "id":"", "method": "getrpcinfo", "params": []}`

    req, _ := http.NewRequest("POST", "http://127.0.0.1:8332/", strings.NewReader(testRequest))
    req.SetBasicAuth("", "notmypassword")
    req.Header.Add("content-type", "text/plain;")

    res, e := http.DefaultClient.Do(req)
    if e != nil {
        fmt.Println(e)
    } else {
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
        fmt.Println(string(body))
    }
}

> **Comments:**
> **username_1**: At lest you could accept your own answer :)  

---

