good morning!!!!

Skip to content
Snippets Groups Projects
Commit a52fae2a authored by a's avatar a
Browse files

organize

parent 18391d0d
No related branches found
Tags v0.1.0
No related merge requests found
......@@ -212,7 +212,7 @@ func (h *handler) handleImmediate(msg *jsonrpcMessage) bool {
}
return false
case msg.isResponse():
h.handleResponse(msg)
h.handleResponse(msg.toResponse())
h.log.Trace().Str("reqid", string(msg.ID.RawMessage())).Dur("duration", time.Since(start)).Msg("Handled RPC response")
return true
default:
......@@ -231,8 +231,7 @@ func (h *handler) handleSubscriptionResult(msg *jsonrpcMessage) {
}
}
// handleResponse processes method call responses.
func (h *handler) handleResponse(msg *jsonrpcMessage) {
func (h *handler) handleResponse(msg *Response) {
op := h.respWait[string(msg.ID.RawMessage())]
if op == nil {
h.log.Debug().Str("reqid", string(msg.ID.RawMessage())).Msg("Unsolicited RPC response")
......@@ -241,7 +240,7 @@ func (h *handler) handleResponse(msg *jsonrpcMessage) {
delete(h.respWait, string(msg.ID.RawMessage()))
if op.sub == nil {
// not a sub, so just send the msg back
op.resp <- msg
op.resp <- msg.Msg()
return
}
// For subscription responses, start the subscription if the server
......
......@@ -52,6 +52,13 @@ func (msg *jsonrpcMessage) isCall() bool {
func (msg *jsonrpcMessage) isResponse() bool {
return msg.hasValidID() && len(msg.Method) == 0 && msg.Params == nil && (msg.Result != nil || msg.Error != nil)
}
func (msg *jsonrpcMessage) toResponse() *Response {
return &Response{
ID: msg.ID,
Result: msg.Result,
Error: msg.Error,
}
}
func (msg *jsonrpcMessage) hasValidID() bool {
return msg.ID != nil && !msg.ID.null
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment