Documentation
¶
Overview ¶
Package rpc is JSON-RPC 2.0 over whole WebSocket messages: one object per frame, no batches. Both Perch daemons (perch-apd, perch-collector) and the controller speak it the same way.
Index ¶
Constants ¶
const ( CodeParseError = -32700 CodeInvalidRequest = -32600 CodeMethodNotFound = -32601 CodeInvalidParams = -32602 CodeInternal = -32603 CodeCommandFailed = -32000 CodeUnsupported = -32001 CodeNotFound = -32002 )
Error codes.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode parses one frame. A parse failure returns a ready-to-send error response (id null).
func Notification ¶
Notification builds a notification message.
Types ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher routes requests to handlers.
func (*Dispatcher) Methods ¶
func (d *Dispatcher) Methods() []string
Methods lists registered method names.
func (*Dispatcher) Register ¶
func (d *Dispatcher) Register(method string, h Handler)
Register adds a method.
type Error ¶
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
Error is a JSON-RPC error object; it is also a Go error.
type Handler ¶
Handler serves one method. Returning an *Error sends it as is; any other error becomes -32000 "command failed".
type Message ¶
type Message struct {
JSONRPC string `json:"jsonrpc"`
ID json.RawMessage `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
Message is any JSON-RPC 2.0 object: request, notification or response.
func (*Message) IsNotification ¶
IsNotification: has a method, no id.