Compare commits

..

No commits in common. '103eb1ec6a7ebea703dfc75a199b11a4ec83eb7b' and '5aa31b3f3ee6519c1dbf5652cf0f5e8bdf68ed22' have entirely different histories.

@ -47,12 +47,8 @@ func (h *HTTPTransport) nextID() uint64 {
return h.nextid
}
func (h *HTTPTransport) Call(method string, args interface{}, reply interface{}) error {
return h.CallWithHeader(method, args, reply, nil)
}
// Call call a remote method
func (h *HTTPTransport) CallWithHeader(method string, args interface{}, reply interface{}, header http.Header) error {
func (h *HTTPTransport) Call(method string, args interface{}, reply interface{}) error {
if args == nil {
args = []string{}
}
@ -61,7 +57,7 @@ func (h *HTTPTransport) CallWithHeader(method string, args interface{}, reply in
Version: "2.0",
Method: method,
Params: args,
ID: h.nextID(),
ID: fmt.Sprintf("%d", h.nextID()),
}
data, err := json.Marshal(r)
@ -78,14 +74,6 @@ func (h *HTTPTransport) CallWithHeader(method string, args interface{}, reply in
return err
}
if header != nil {
for k, v := range header {
for _, v1 := range v {
req.Header.Add(k, v1)
}
}
}
req.Header.Set("Content-Type", "application/json")
resp, err := h.Client.Do(req)

@ -22,14 +22,14 @@ type request struct {
Version string `json:"jsonrpc"`
Method string `json:"method"`
Params interface{} `json:"params"`
ID uint64 `json:"id"`
ID string `json:"id"`
}
type response struct {
Version string `json:"jsonrpc"`
Result json.RawMessage `json:"result"`
Error *Error `json:"error"`
ID uint64 `json:"id"`
ID string `json:"id"`
Method string `json:"method"`
Params json.RawMessage `json:"params"`
}

@ -17,7 +17,7 @@ type WebsocketTransport struct {
Conn *websocket.Conn
URL string
Mu *sync.Mutex
inflight map[uint64]*inflightReq
inflight map[string]*inflightReq
nextid uint64
err error
ctx context.Context
@ -52,7 +52,7 @@ func NewWebsocketTransport(ctx context.Context, uri string) (Transport, error) {
w := &WebsocketTransport{
Conn: conn,
URL: uri,
inflight: make(map[uint64]*inflightReq),
inflight: make(map[string]*inflightReq),
subscribes: make(map[string][]*inflightReq),
Mu: new(sync.Mutex),
}
@ -96,7 +96,7 @@ func (h *WebsocketTransport) readloop() {
return
}
if res.ID != 0 {
if res.ID != "" {
// response
h.Mu.Lock()
@ -173,7 +173,7 @@ func (h *WebsocketTransport) Call(method string, args interface{}, reply interfa
return h.err
}
id := h.nextID()
id := fmt.Sprintf("%d", h.nextID())
req := request{
ID: id,
Version: "2.0",
@ -191,7 +191,7 @@ func (h *WebsocketTransport) Call(method string, args interface{}, reply interfa
h.Mu.Lock()
h.inflight[id] = &inflightReq{
id: fmt.Sprintf("%d", id),
id: id,
ch: ch,
errch: errch,
}

Loading…
Cancel
Save