diff options
author | jon4hz <me@jon4hz.io> | 2022-06-28 19:55:30 +0300 |
---|---|---|
committer | jon4hz <me@jon4hz.io> | 2022-06-28 19:55:30 +0300 |
commit | 40ab2c6e61d8fcaddf7daac1cc7919f949c44124 (patch) | |
tree | 3448b0c3d7569af25ee5579d3ed2c0f3d077b58f /rpc/wrapper.go | |
parent | c39fcbc6a153b11354fa46e69a332ebc3774fdcb (diff) |
feat: add wrapper supporting no request params
Diffstat (limited to 'rpc/wrapper.go')
-rw-r--r-- | rpc/wrapper.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/rpc/wrapper.go b/rpc/wrapper.go index 8aa9556..f16833f 100644 --- a/rpc/wrapper.go +++ b/rpc/wrapper.go @@ -41,4 +41,18 @@ func H[RQ any, RS any](handler func(context.Context, *RQ) (RS, error)) HandlerFu } } +// HS is a simple generic wrapper for rpc handlers without any request params. +func HS[RS any](handler func(context.Context) (RS, error)) HandlerFunc { + return func(ctx context.Context, in json.RawMessage) (json.RawMessage, error) { + resp, err := handler(ctx) + if err != nil { + return nil, Error{ + Code: ErrUser, + Message: err.Error(), + } + } + return json.Marshal(resp) + } +} + type HandlerFunc func(context.Context, json.RawMessage) (json.RawMessage, error) |