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

Adjust Handler interface and support middleware

This commit is contained in:
Ggicci 2022-01-23 16:36:45 +08:00
parent c9c77b6bb9
commit 4188fa4438
8 changed files with 127 additions and 46 deletions

View file

@ -56,13 +56,13 @@ func TestPlainObjectCodec(t *testing.T) {
// echoHandler unmarshals the request's params object and echos the object
// back as the response's result.
var echoHandler handlerFunc = func(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) {
var echoHandler handlerFunc = func(conn *jsonrpc2.Conn, req *jsonrpc2.Request) {
msg := &Message{}
if err := json.Unmarshal(*req.Params, msg); err != nil {
conn.ReplyWithError(ctx, req.ID, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidRequest, Message: err.Error()})
conn.ReplyWithError(req.Context(), req.ID, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidRequest, Message: err.Error()})
return
}
conn.Reply(ctx, req.ID, msg)
conn.Reply(req.Context(), req.ID, msg)
}
connB := jsonrpc2.NewConn(
context.Background(),