1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-06-18 21:20:02 +02:00

fix some golangci-lint, revive linter warnings

Signed-off-by: s3rj1k <evasive.gyron@gmail.com>
This commit is contained in:
s3rj1k 2019-11-02 22:31:21 +02:00
parent 35a74f039c
commit 456318691a
4 changed files with 43 additions and 36 deletions

View file

@ -84,11 +84,12 @@ func (r *Request) UnmarshalJSON(data []byte) error {
return err
}
r.Method = r2.Method
if r2.Params == nil {
switch {
case r2.Params == nil:
r.Params = &jsonNull
} else if len(*r2.Params) == 0 {
case len(*r2.Params) == 0:
r.Params = nil
} else {
default:
r.Params = r2.Params
}
r.Meta = r2.Meta
@ -212,22 +213,22 @@ func (e *Error) Error() string {
return fmt.Sprintf("jsonrpc2: code %v message: %s", e.Code, e.Message)
}
// Errors defined in the JSON-RPC spec. See
// http://www.jsonrpc.org/specification#error_object.
const (
// Errors defined in the JSON-RPC spec. See
// http://www.jsonrpc.org/specification#error_object.
CodeParseError = -32700
CodeInvalidRequest = -32600
CodeMethodNotFound = -32601
CodeInvalidParams = -32602
CodeInternalError = -32603
codeServerErrorStart = -32099
codeServerErrorEnd = -32000
CodeParseError = -32700
CodeInvalidRequest = -32600
CodeMethodNotFound = -32601
CodeInvalidParams = -32602
CodeInternalError = -32603
// codeServerErrorStart = -32099
// codeServerErrorEnd = -32000
)
// Handler handles JSON-RPC requests and notifications.
type Handler interface {
// Handle is called to handle a request. No other requests are handled
// until it returns. If you do not require strict ordering behaviour
// until it returns. If you do not require strict ordering behavior
// of received RPCs, it is suggested to wrap your handler in
// AsyncHandler.
Handle(context.Context, *Conn, *Request)
@ -345,7 +346,7 @@ func (c *Conn) Close() error {
return c.stream.Close()
}
func (c *Conn) send(ctx context.Context, m *anyMessage, wait bool) (cc *call, err error) {
func (c *Conn) send(_ context.Context, m *anyMessage, wait bool) (cc *call, err error) {
c.sending.Lock()
defer c.sending.Unlock()
@ -441,7 +442,6 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface
if call.response.Result == nil {
call.response.Result = &jsonNull
}
// TODO(sqs): error handling
if err := json.Unmarshal(*call.response.Result, result); err != nil {
return err
}
@ -642,17 +642,18 @@ func (m *anyMessage) UnmarshalJSON(data []byte) error {
if len(msgs) == 0 {
return errors.New("jsonrpc2: invalid empty batch")
}
for _, msg := range msgs {
if err := checkType(&msg); err != nil {
for i := range msgs {
var m = msgs[i]
if err := checkType(&m); err != nil {
return err
}
}
} else {
var msg msg
if err := json.Unmarshal(data, &msg); err != nil {
var m msg
if err := json.Unmarshal(data, &m); err != nil {
return err
}
if err := checkType(&msg); err != nil {
if err := checkType(&m); err != nil {
return err
}
}
@ -694,7 +695,10 @@ func (v *anyValueWithExplicitNull) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &v.value)
}
/*
var (
errInvalidRequestJSON = errors.New("jsonrpc2: request must be either a JSON object or JSON array")
errInvalidResponseJSON = errors.New("jsonrpc2: response must be either a JSON object or JSON array")
)
*/