package
0.2.2
Repository: https://github.com/companyzero/bisonrelay.git
Documentation: pkg.go.dev

# README

JSON-RPC 2.0 clientrpc transport

jsonrpc package implements JSON-RPC 2.0 clients and servers for automating a Bison Relay client activities, such as writing bots, interfacing with third party systems, and so on.

The server side of this package runs inside BR clients (such as brclient) while the client side may be used by other applications, such as bot daemons, to connect to and perform BR-related operations (such as sending and receiving PMs, GC messages, etc).

End-users are generally interested in the client side of this package. Currently, a single client mode is provided, which uses a websockets-based transport. This transport allows both unary requests and client-initiated server streams (requests where the server may stream data back to the client at arbitrary times).

Example Client

Following is the simplest example for creating a new client, connecting to a brclient instance with the JSON-RPC enabled and using client certficate authentication. Error handling is omitted for brevity:

	c, _ := jsonrpc.NewWSClient(
		jsonrpc.WithWebsocketURL("wss://127.0.0.1:7676"),
		jsonrpc.WithServerTLSCertPath("/path/to/rpc.cert"),
		jsonrpc.WithClientTLSCert("/path/to/rpc-client.cert",
        "/path/to/rpc-client.key"),
	)
    go c.Run(context.Background())
	vc := types.NewVersionServiceClient(c)
    res := &types.VersionResponse{}
	_ = vc.Version(context.Background(), nil, res)
    fmt.Println(res)

Example curl call

$ curl \
    --cert ~/.brclient/rpc-client.cert \
    --key ~/.brclient/rpc-client.key \
    --cacert ~/.brclient/rpc.cert \
    --data-binary '{"jsonrpc":"2.0","id":"dummy_id","method":"VersionService.Version","params":{}}' \
    https://127.0.0.1:7676/index

# Functions

MakeError creates a JSON-RPC Error with the given code and message.
NewServer returns a new JSON-RPC server.
NewWSClient creates a new Websockets-based JSON-RPC 2.0 client.
WithClientLog defines the logger to use to log client-related debug messages.
WithClientTLSCert defines the path to the client certificate and key to use to authenticate against the server.
WithListeners defines which listeners to bind the server to.
WithServerLog defines the logger to use to log server debug messages.
WithServerTLSCertPath defines the path to the certificate file to use to connect to the server.
WithServices defines the service map to use on the server.
WithWebsocketURL defines the URL to use to connect to the clientrpc server.

# Constants

Application defined error codes.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
JSON-RPC defined error codes.

# Structs

Error is a JSON-RPC error response.
Server is a JSON-RPC 2.0 server.
WSClient is a websockets-based bidirectional JSON-RPC 2.0 client.

# Type aliases

ClientOption is a configuration option for JSON-RPC clients.
ErrorCode is a JSON-RPC error code.
ServerOption defines an option when configuring a JSON-RPC server.