Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MethodDef ¶
type MethodHandler ¶
type MethodHandler func(ctx context.Context, s *Server) (argsPtr any, handler func() (any, *jsonrpc.Error))
MethodHandler is a type of function that returns an interface containing a pointer to a handler's input arguments, and a handler function that captures the arguments pointer. The handler function returns its result type in an interface, and a *jsonrpc.Error. A simple MethodHandler would instantiate a new concrete instance of the parameters type and define a function that uses that instance to perform some operations.
func InspectHandler ¶
func MakeMethodHandler ¶
func MakeMethodHandler[I, O any](fn Handler[I, O]) MethodHandler
type Opt ¶
type Opt func(*serverConfig)
func WithPass ¶
WithPass will require a password in the request header's Authorization value in "Basic" formatting. Don't use this without TLS; either terminate TLS in an upstream reverse proxy, or use WithTLS with Certificates provided.
func WithServerInfo ¶
WithServerInfo sets the OpenRPC "info" section to use when serving the OpenRPC JSON specification either via a spec REST endpoint or the rpc.discover JSON-RPC method.
func WithTLS ¶
WithTLS provides a tls.Config to use with tls.NewListener around the standard net.Listener.
func WithTimeout ¶
WithTimeout specifies a timeout on all RPC requests that when exceeded will cancel the request.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a JSON-RPC server.
func NewServer ¶
NewServer creates a new JSON-RPC server. Use RegisterMethodHandler or RegisterSvc to add method handlers.
func (*Server) RegisterMethodHandler ¶
func (s *Server) RegisterMethodHandler(method jsonrpc.Method, h MethodHandler)
RegisterMethodHandler registers a single MethodHandler. See also RegisterSvc.
func (*Server) RegisterSvc ¶
RegisterSvc registers every MethodHandler for a service.
The Server's fixed endpoint is used.
type Svc ¶
Svc is a type that enumerates its handler functions by method name. To handle a method, the Server:
- retrieves the MethodHandler associated with the method
- calls the MethodHandler to get the args interface and handler function
- unmarshals the inputs from a json.RawMessage into the args interface
- calls the handler function, returning the result and error
- marshal either the result or the Error into a Response