Documentation
¶
Index ¶
- Constants
- Variables
- func DebugCodec(labelPrefix string, codec Codec) *debugCodec
- func IOCodec(rwc io.ReadWriteCloser) *jsonCodec
- func IsErrorCode(err error, allowedCodes ...int) bool
- func Methods(receiver interface{}) (map[string]Method, error)
- func ServePipe() (*Remote, *Remote)
- func SetLogger(w io.Writer)
- type Client
- type Codec
- type ContextMissingValueError
- type ErrResponse
- type ErrorCode
- type HTTPRequestError
- type HTTPServer
- type HTTPService
- type Handler
- type Local
- type Message
- type Method
- type Remote
- type Request
- type Requester
- type Response
- type Server
- type Service
Constants ¶
const ( ErrCodeParse int = -32700 ErrCodeInvalidRequest = -32600 ErrCodeMethodNotFound = -32601 ErrCodeInvalidParams = -32602 ErrCodeInternal = -32603 ErrCodeServer = -32000 )
const Version = "2.0"
Variables ¶
var ErrNoPublicMethods = errors.New("no public methods")
Functions ¶
func DebugCodec ¶
DebugCodec logs each incoming and outgoing message with a given label prefix (use something like the IP address or user ID).
func IOCodec ¶
func IOCodec(rwc io.ReadWriteCloser) *jsonCodec
IOCodec returns a Codec that wraps JSON encoding and decoding over IO.
func IsErrorCode ¶ added in v0.2.2
IsErrorCode returns true iff the error has an ErrorCode. If allowedCodes is provided, then it also checks that it matches one of the allowedCodes.
func Methods ¶
Methods returns a mapping of valid method names to Method definitions for a instance's receiver.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is responsible for making request messages.
type Codec ¶
type Codec interface { ReadMessage() (*Message, error) WriteMessage(*Message) error Close() error RemoteAddr() string }
Codec is an straction for receiving and sending JSONRPC messages.
type ContextMissingValueError ¶ added in v0.2.6
type ContextMissingValueError struct {
Key serviceContext
}
ContextMissingValueError is returned when a context is missing an expected value.
func (ContextMissingValueError) Error ¶ added in v0.2.6
func (err ContextMissingValueError) Error() string
type ErrResponse ¶
type ErrResponse struct { Code int `json:"code"` Message string `json:"message"` Data json.RawMessage `json:"data,omitempty"` }
ErrResponse is returned as part of a Response message when there is an error.
func (*ErrResponse) Error ¶
func (err *ErrResponse) Error() string
func (*ErrResponse) ErrorCode ¶
func (err *ErrResponse) ErrorCode() int
type HTTPRequestError ¶ added in v0.2.2
HTTPRequestError is used when RPC over HTTP encounters an error during transport.
func (HTTPRequestError) Error ¶ added in v0.2.2
func (err HTTPRequestError) Error() string
type HTTPServer ¶ added in v0.2.2
type HTTPServer struct { Server // MaxContentLength is the request size limit (optional) MaxContentLength int64 }
HTTPServer provides a JSONRPC2 server over HTTP by implementing http.Handler.
func (*HTTPServer) ServeHTTP ¶ added in v0.2.2
func (h *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
type HTTPService ¶ added in v0.2.2
type Handler ¶
type Handler interface { // Handle takes a request message and returns a response message. Handle(ctx context.Context, request *Message) (response *Message) // FIXME: Register* really shouldn't be part of this signature, right? Register(prefix string, receiver interface{}) error RegisterMethod(rpcName string, receiver interface{}, methodName string) error }
Handler is a server that executes an RPC request message, returning an RPC response message.
type Message ¶
type Message struct { *Request *Response ID json.RawMessage `json:"id,omitempty"` Version string `json:"jsonrpc"` // TODO: Replace this with a null-type that encodes to 2.0, like https://go-review.googlesource.com/c/tools/+/136675/1/internal/jsonrpc2/jsonrpc2.go#221 }
type Method ¶
type Method struct { Receiver reflect.Value Method reflect.Method ArgTypes []reflect.Type ErrPos int HasCtx bool }
Method is the definition of a callable method.
func MethodByName ¶
MethodByName returns a single Method from receiver that matches the name.
type Remote ¶
type Remote struct { Codec Client Requester Server Handler // PendingLimit is the number of messages to hold before oldest messages get discarded. PendingLimit int // PendingDiscard is the number of oldest messages that get discarded when PendingLimit is reached. PendingDiscard int // contains filtered or unexported fields }
Remote is a wrapper around a connection that can be both a Client and a Server. It implements the Service interface, and manages async message routing.
type Request ¶
type Request struct { Method string `json:"method"` Params json.RawMessage `json:"params,omitempty"` }
type Response ¶
type Response struct { Result json.RawMessage `json:"result,omitempty"` Error *ErrResponse `json:"error,omitempty"` }
func (*Response) UnmarshalResult ¶ added in v0.2.2
UnmarshalResult attempts to convert the message into a successful result unmarshal. If the message is not a success type (or if unmarshal fails), then an appropriate error will be returned.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server contains the method registry.