Documentation
¶
Index ¶
- Constants
- func Mount(target route.Target, server *Server, options ...MountOption)
- func Provider(server *Server, options ...Option) runaprovider.Provider
- type Config
- type Context
- type Error
- type Handler
- type ID
- type Middleware
- type MountConfig
- type MountOption
- type Option
- type Registry
- type Request
- type Response
- type Server
- func (server *Server) Call(ctx context.Context, method string, params any) (any, error)
- func (server *Server) HTTP() route.Handler
- func (server *Server) Register(name string, handler Handler) *Server
- func (server *Server) Use(middlewares ...Middleware) *Server
- func (server *Server) WS(options ...WSOption) route.Handler
- type TypedHandler
- type WSConfig
- type WSOption
Constants ¶
const ( CodeParseError = -32700 CodeInvalidRequest = -32600 CodeMethodNotFound = -32601 CodeInvalidParams = -32602 CodeInternalError = -32603 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Path string `toml:"path"`
WSPath string `toml:"ws_path"`
WSOptions []WSOption `toml:"-"`
}
Config configures JSON-RPC route mounting.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context stores one JSON-RPC call context.
func (*Context) SetContext ¶
SetContext replaces the current call context.
type Error ¶
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
Error is a JSON-RPC 2.0 error object.
type MountConfig ¶
MountConfig configures JSON-RPC mounting on a route target.
type MountOption ¶
type MountOption func(*MountConfig)
MountOption configures JSON-RPC route mounting.
func WebSocket ¶
func WebSocket(path string, options ...WSOption) MountOption
WebSocket mounts a JSON-RPC WebSocket endpoint under target.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores app-scoped JSON-RPC servers.
type Request ¶
type Request struct {
Version string `json:"jsonrpc,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
ID ID `json:"id,omitempty"`
}
Request is a JSON-RPC 2.0 request object.
type Response ¶
type Response struct {
Version string `json:"jsonrpc"`
Result any `json:"-"`
Error *Error `json:"error,omitempty"`
ID ID `json:"id"`
}
Response is a JSON-RPC 2.0 response object.
func (Response) MarshalJSON ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server stores JSON-RPC methods.
func Method ¶
func Method[Input any, Output any](server *Server, name string, handler TypedHandler[Input, Output]) *Server
Method registers a typed JSON-RPC method.
func (*Server) Use ¶
func (server *Server) Use(middlewares ...Middleware) *Server
Use adds JSON-RPC method middleware.
type TypedHandler ¶
TypedHandler handles a typed JSON-RPC method call.
type WSConfig ¶
type WSConfig struct {
Origin []string
MaxMessageSize int64
ReadTimeout time.Duration
WriteTimeout time.Duration
}
WSConfig configures JSON-RPC over WebSocket.
type WSOption ¶
type WSOption func(*WSConfig)
WSOption configures JSON-RPC WebSocket transport.
func MaxMessageSize ¶
MaxMessageSize sets max WebSocket message size.
func ReadTimeout ¶
ReadTimeout sets WebSocket read timeout.
func WriteTimeout ¶
WriteTimeout sets WebSocket write timeout.