 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnknown = NewError(-32001, "JSON RPC unknown error") ErrParse = NewError(-32700, "JSON RPC parse error") ErrInvalidRequest = NewError(-32600, "JSON RPC invalid request") ErrMethodNotFound = NewError(-32601, "JSON RPC method not found") ErrInvalidParams = NewError(-32602, "JSON RPC invalid params") ErrInternal = NewError(-32603, "JSON RPC internal error") )
Functions ¶
This section is empty.
Types ¶
type ChanObjStream ¶
type ChanObjStream struct {
	// contains filtered or unexported fields
}
    This is mostly intented as a testing utility
func NewChanObjStream ¶
func NewChanObjStream(in <-chan Message, out chan<- Message) *ChanObjStream
func (*ChanObjStream) Close ¶
func (c *ChanObjStream) Close() error
func (*ChanObjStream) ReadMessage ¶
func (c *ChanObjStream) ReadMessage() (Message, error)
func (*ChanObjStream) WriteMessage ¶
func (c *ChanObjStream) WriteMessage(obj Message) error
type Conn ¶
type Conn struct {
	// contains filtered or unexported fields
}
    func NewConn ¶
func NewConn(objStream MessageStream, handlers ...Handler) *Conn
Starts listening asynchronously to the MessageStream and returns the connection.
By default, the server will try write concurrently to the ObjectStream
func (*Conn) SendNotification ¶
Send a json rpc request and wait for the message to be sent. Thread safe
Will panick whenever the params object fails json.Marshal-ing
func (*Conn) SendRequest ¶
func (s *Conn) SendRequest(method string, params any) (json.RawMessage, *ResponseError)
Send a json rpc request and wait for the response. Thread safe.
Will panick whenever the params object fails json.Marshal-ing
type Handler ¶
type Handler struct {
	// contains filtered or unexported fields
}
    func NewNotificationHandler ¶
func NewNotificationHandler[Params any](method string, strategy HandlingStrategy, handler func(params Params, conn *Conn)) Handler
Create a notification handler for the given method
The handler will be called asynchronously
func NewRequestHandler ¶
func NewRequestHandler[Params any](method string, strategy HandlingStrategy, handler func(params Params, conn *Conn) any) Handler
Create a request handler for the given method
The handler will be called asynchronously. Will panic if not able to marshal the handler's return value
type HandlingStrategy ¶
type HandlingStrategy uint8
const ( SyncHandling HandlingStrategy = iota AsyncHandling )
type Message ¶
type Message interface {
	// contains filtered or unexported methods
}
    func UnmarshalMessage ¶
type MessageStream ¶
type Request ¶
type Request struct {
	// ID of this request, used to tie the Response back to the request.
	// This will be nil for notifications.
	ID ID
	// Method is a string containing the method name to invoke.
	Method string
	// Params is either a struct or an array with the parameters of the method.
	Params json.RawMessage
}
    func (Request) IsNotification ¶
func (Request) MarshalJSON ¶
type Response ¶
type Response struct {
	// result is the content of the response.
	Result json.RawMessage
	// err is set only if the call failed.
	Error *ResponseError
	// id of the request this is a response to.
	ID ID
}
    https://www.jsonrpc.org/specification#response_object
func (Response) MarshalJSON ¶
type ResponseError ¶
type ResponseError struct {
	Code    int64           `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
}
    https://www.jsonrpc.org/specification#error_object
func NewError ¶
func NewError(code int64, message string) ResponseError