'GoLang | Transferring the data coming with the post to the interface
I'm doing a post operation like this, can you let me know how I can carry it to the interface?
I tried many ways, I gave any type without string. I'm a little new to this language, I created the logic but I couldn't apply it...
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
const (
RPC_URL string = "https://rpc.blurt.world"
)
func main() {
values := map[string]string{
"jsonrpc": "2.0",
"id": "1",
"method": "condenser_api.get_account_history",
"params": `["post24", -1, 10]`,
}
jsonValue, _ := json.Marshal(values)
resp, err := http.Post(RPC_URL, "application/json", bytes.NewBuffer(jsonValue))
if err != nil {
fmt.Printf("wanted in error http post request: %v", err)
}
// defer resp.Body.Close()
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
}
}(resp.Body)
var response map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
fmt.Printf("wanted in error json decode: %v", err)
}
fmt.Printf("%v", response)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
