You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// * For some connection errors, go-jsonrpc will return jsonrpc.RPCConnectionError{}.
83
83
// * RPC-returned errors will be constructed with basic errors.New(__"string message"__)
84
84
// * JSON-RPC error codes can be mapped to typed errors with jsonrpc.Errors - https://pkg.go.dev/github.com/filecoin-project/go-jsonrpc#Errors
85
85
// * For typed errors to work, server needs to be constructed with the `WithServerErrors`
86
86
// option, and the client needs to be constructed with the `WithErrors` option
87
87
Func3() error
88
-
88
+
89
89
// Returning a value
90
90
// Note: The value must be serializable with encoding/json.
91
91
Func4() int
92
-
92
+
93
93
// Returning a value and an error
94
94
// Note: if the handler returns an error and a non-zero value, the value will not
95
95
// be returned to the client - the client will see a zero value.
96
96
Func4() (int, error)
97
-
97
+
98
98
// With context
99
99
// * Context isn't passed as JSONRPC param, instead it has a number of different uses
100
100
// * When the context is cancelled on the client side, context cancellation should propagate to the server handler
@@ -103,9 +103,9 @@ type _ interface {
103
103
// * If the context contains an opencensus trace span, it will be propagated to the server through a
104
104
// `"Meta": {"SpanContext": base64.StdEncoding.EncodeToString(propagation.Binary(span.SpanContext()))}` field in
105
105
// the jsonrpc request
106
-
//
106
+
//
107
107
Func5(ctx context.Context, param1 string) error
108
-
108
+
109
109
// With non-json-serializable (e.g. interface) params
110
110
// * There are client and server options which make it possible to register transformers for types
111
111
// to make them json-(de)serializable
@@ -115,7 +115,7 @@ type _ interface {
115
115
// which will pass reader data through separate http streams on a different hanhler.
116
116
// * Note: a similar mechanism for return value transformation isn't supported yet
117
117
Func6(r io.Reader)
118
-
118
+
119
119
// Returning a channel
120
120
// * Only supported in websocket mode
121
121
// * If no error is returned, the return value will be an int channelId
@@ -132,12 +132,13 @@ type _ interface {
132
132
```
133
133
134
134
### Custom Transport Feature
135
+
135
136
The go-jsonrpc library supports creating clients with custom transport mechanisms (e.g. use for IPC). This allows for greater flexibility in how requests are sent and received, enabling the use of custom protocols, special handling of requests, or integration with other systems.
136
137
137
138
#### Example Usage of Custom Transport
138
139
139
140
Here is an example demonstrating how to create a custom client with a custom transport mechanism:
140
-
141
+
141
142
```go
142
143
// Setup server
143
144
serverHandler:= &SimpleServerHandler{} // some type with methods
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.
179
181
180
182
NOTE: Reverse calling only works in websocket mode
0 commit comments