This commit is contained in:
crusader 2017-11-01 18:58:16 +09:00
parent 8712bafeb6
commit 93cffbb1e5
3 changed files with 15 additions and 7 deletions

View File

@ -22,7 +22,7 @@ type ClientCodecResponseOrNotify interface {
type ClientCodecResponse interface {
ID() interface{}
Result() interface{}
Result(result interface{}) error
Error() error
Complete()
}

View File

@ -33,7 +33,7 @@ type clientRequest struct {
// clientResponse represents a JSON-RPC response returned to a client.
type clientResponse struct {
Version string `json:"jsonrpc"`
Result interface{} `json:"result,omitempty"`
Result *json.RawMessage `json:"result,omitempty"`
Error error `json:"error,omitempty"`
ID interface{} `json:"id"`
}

View File

@ -47,8 +47,16 @@ func (ccr *ClientCodecResponse) ID() interface{} {
return ccr.response.ID
}
func (ccr *ClientCodecResponse) Result() interface{} {
return ccr.response.Result
func (ccr *ClientCodecResponse) Result(result interface{}) error {
if ccr.err == nil && ccr.response.Result != nil {
if err := json.Unmarshal(*ccr.response.Result, result); err != nil {
params := [1]interface{}{result}
if err = json.Unmarshal(*ccr.response.Result, &params); err != nil {
ccr.err = err
}
}
}
return ccr.err
}
func (ccr *ClientCodecResponse) Error() error {