Skip to content

Commit b710b30

Browse files
committed
docs: update README.md to enhance reverse calling feature description and add method name formatter options
1 parent 6cf87e3 commit b710b30

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fmt.Printf("Current value: %d\n", client.AddGet(5))
175175
```
176176

177177
### Reverse Calling Feature
178-
The go-jsonrpc library also supports reverse calling, where the server can make calls to the client. This is useful in scenarios where the server needs to notify or request data from the client.
178+
The go-jsonrpc library also supports reverse calling, where the server can make calls to the client. This is useful in scenarios where the server needs to notify, request data from the client, or for subscriptions (e.g. `eth_subscribe`).
179179

180180
NOTE: Reverse calling only works in websocket mode
181181

@@ -246,11 +246,13 @@ if err := client.Call(); err != nil {
246246

247247
## Options
248248

249-
### Using `WithServerMethodNameFormatter`
249+
### Using method name formatters
250+
251+
#### Using `WithServerMethodNameFormatter`
250252

251253
`WithServerMethodNameFormatter` allows you to customize a function that formats the JSON-RPC method name, given namespace and method name.
252254

253-
There are four possible options:
255+
There are four possible out-of-the-box options:
254256
- `jsonrpc.DefaultMethodNameFormatter` - default method name formatter, e.g. `SimpleServerHandler.AddGet`
255257
- `jsonrpc.NewMethodNameFormatter(true, jsonrpc.LowerFirstCharCase)` - method name formatter with namespace, e.g. `SimpleServerHandler.addGet`
256258
- `jsonrpc.NewMethodNameFormatter(false, jsonrpc.OriginalCase)` - method name formatter without namespace, e.g. `AddGet`
@@ -261,6 +263,8 @@ There are four possible options:
261263
> Go exported methods are capitalized, so, the method name will be capitalized as well.
262264
> e.g. `SimpleServerHandler.AddGet` (capital "A" in "AddGet")
263265
266+
You can also create your own method name formatter by creating a function that implements the `jsonrpc.MethodNameFormatter` interface.
267+
264268
```go
265269
func main() {
266270
// create a new server instance with a custom separator
@@ -286,7 +290,7 @@ func main() {
286290
}
287291
```
288292

289-
### Using `WithMethodNameFormatter`
293+
#### Using `WithMethodNameFormatter`
290294

291295
`WithMethodNameFormatter` is the client-side counterpart to `WithServerMethodNameFormatter`.
292296

@@ -304,6 +308,27 @@ func main() {
304308
}
305309
```
306310

311+
#### Using `WithClientHandlerFormatter`
312+
313+
Same as `WithMethodNameFormatter`, but for client handlers. Using it you can fully customize the JSON-RPC method name for client handlers,
314+
given namespace and method name.
315+
316+
```go
317+
func main() {
318+
closer, err := jsonrpc.NewMergeClient(
319+
context.Background(),
320+
"http://example.com",
321+
"SimpleServerHandler",
322+
[]any{&client},
323+
nil,
324+
jsonrpc.WithMethodNameFormatter(jsonrpc.NewMethodNameFormatter(false, OriginalCase)),
325+
jsonrpc.WithClientHandler("Client", &RevCallTestClientHandler{}),
326+
jsonrpc.WithClientHandlerFormatter(jsonrpc.NewMethodNameFormatter(false, OriginalCase)),
327+
)
328+
defer closer()
329+
}
330+
```
331+
307332
## Contribute
308333

309334
PRs are welcome!

0 commit comments

Comments
 (0)