aboutsummaryrefslogtreecommitdiff
path: root/rpc
diff options
context:
space:
mode:
authorAlex <i@neonxp.dev>2022-06-30 19:12:28 +0300
committerGitHub <noreply@github.com>2022-06-30 19:12:28 +0300
commit3d69d1e7eabf8dbf1cb502a87787fe9ed120edc8 (patch)
tree0c1b7a657b5e019484e935996323420874b5ef57 /rpc
parent058331685cbdb73a4610110eb5599c0628e51c26 (diff)
parent7c86c2bfcf7be89492bc3df54ad3aaaf8a589043 (diff)
Merge pull request #3 from jon4hz/feat-no-paramsv1.2.0
feat: add wrapper supporting no request params
Diffstat (limited to 'rpc')
-rw-r--r--rpc/wrapper.go14
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)