2

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

1 Answer 1

4

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))
    }
}
1
  • At lest you could accept your own answer :)
    – Ron
    Commented May 10, 2022 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.