Add a simple RPC request helper.

Signed-off-by: Sayan Biswas <sayan@pokurt.me>
This commit is contained in:
Sayan Biswas 2021-10-28 17:18:03 +05:30
parent 522e06aae5
commit d9cb0aae90
No known key found for this signature in database
GPG Key ID: E1220C019C89B488
2 changed files with 31 additions and 1 deletions

View File

@ -1,6 +1,6 @@
package client
const (
RPC_ENDPOINT = "https://socialvoid.qlg1.com:5601/"
RPC_ENDPOINT = "http://socialvoid.qlg1.com:5601/"
VERSION = "0.0.1"
)

30
client/helpers/request.go Normal file
View File

@ -0,0 +1,30 @@
package helpers
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
)
type RPCMethod struct {
Method string `json:"method"`
Params interface{} `json:"params"`
}
func DoRequest(url string, r *RPCMethod) (interface{}, error) {
j, err := json.Marshal(r.Params)
if err != nil {
return nil, err
}
resp, err := http.Post(url, "application/json-rpc", bytes.NewBuffer(j))
if err != nil {
return nil, err
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return b, nil
}