Add a simple RPC request helper.
Signed-off-by: Sayan Biswas <sayan@pokurt.me>
This commit is contained in:
parent
522e06aae5
commit
d9cb0aae90
|
@ -1,6 +1,6 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RPC_ENDPOINT = "https://socialvoid.qlg1.com:5601/"
|
RPC_ENDPOINT = "http://socialvoid.qlg1.com:5601/"
|
||||||
VERSION = "0.0.1"
|
VERSION = "0.0.1"
|
||||||
)
|
)
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue