1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-06-16 04:04:56 +02:00

remove incorrect special handling of null results

It is not correct in general to convert null results in JSON-RPC 2.0 responses to `{}`.
This commit is contained in:
Quinn Slack 2017-01-22 15:00:12 -08:00
parent d58e8cc226
commit c0f3aff61f

View file

@ -3,7 +3,6 @@ package jsonrpc2
import (
"context"
"log"
"reflect"
)
// HandlerWithError implements Handler by calling the func for each
@ -22,9 +21,6 @@ func (h HandlerWithError) Handle(ctx context.Context, conn *Conn, req *Request)
resp := &Response{ID: req.ID}
if err == nil {
if isNilValue(result) {
result = struct{}{}
}
err = resp.SetResult(result)
}
if err != nil {
@ -41,17 +37,3 @@ func (h HandlerWithError) Handle(ctx context.Context, conn *Conn, req *Request)
}
}
}
// isNilValue tests if an interface is empty, because an empty interface does
// not encode any information, we can't encode it in JSON so that the proxy
// knows it's a response, not a request.
func isNilValue(resp interface{}) bool {
if resp == nil {
return true
}
kind := reflect.TypeOf(resp).Kind()
value := reflect.ValueOf(resp)
nilPtr := kind == reflect.Ptr && value.IsNil()
nilSlice := kind == reflect.Slice && value.IsNil()
return nilPtr || nilSlice
}