From 4cf58de9bb7b109dddbc80adefe52cdf61328d0d Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Mon, 31 Jan 2022 20:17:31 +0300 Subject: Small refactoring --- wrapper.go | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 wrapper.go (limited to 'wrapper.go') diff --git a/wrapper.go b/wrapper.go deleted file mode 100644 index 8058a27..0000000 --- a/wrapper.go +++ /dev/null @@ -1,25 +0,0 @@ -package jsonrpc2 - -import ( - "context" - "encoding/json" -) - -func Wrap[RQ any, RS any](handler func(context.Context, *RQ) (RS, error)) Handler { - return func(ctx context.Context, in json.RawMessage) (json.RawMessage, error) { - req := new(RQ) - if err := json.Unmarshal(in, req); err != nil { - return nil, NewError(ErrCodeParseError) - } - resp, err := handler(ctx, req) - if err != nil { - return nil, Error{ - Code: ErrUser, - Message: err.Error(), - } - } - return json.Marshal(resp) - } -} - -type Handler func(context.Context, json.RawMessage) (json.RawMessage, error) -- cgit v1.2.3