mirror of
https://github.com/sourcegraph/jsonrpc2.git
synced 2026-07-04 00:03:41 +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:
parent
d58e8cc226
commit
c0f3aff61f
1 changed files with 0 additions and 18 deletions
|
|
@ -3,7 +3,6 @@ package jsonrpc2
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
"reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandlerWithError implements Handler by calling the func for each
|
// 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}
|
resp := &Response{ID: req.ID}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if isNilValue(result) {
|
|
||||||
result = struct{}{}
|
|
||||||
}
|
|
||||||
err = resp.SetResult(result)
|
err = resp.SetResult(result)
|
||||||
}
|
}
|
||||||
if err != nil {
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue