Documentation
¶
Index ¶
Constants ¶
View Source
const ( ErrorParseError = -32700 ErrorInvalidRequest = -32600 ErrorMethodNotFound = -32601 ErrorInvalidParams = -32602 ErrorInternalError = -32603 )
Error codes
View Source
const ProtocolVersion = "1.0"
ProtocolVersion 当前协议版本
Variables ¶
This section is empty.
Functions ¶
func EncodeResponse ¶
func EncodeResponse(resp *JSONRPCResponse) ([]byte, error)
EncodeResponse 编码响应
Types ¶
type Connection ¶
Connection WebSocket 连接
func NewConnection ¶
func NewConnection(ws *websocket.Conn, cfg *WebSocketConfig) *Connection
NewConnection 创建连接
func (*Connection) SendJSON ¶
func (c *Connection) SendJSON(v interface{}) error
SendJSON 发送 JSON 消息
func (*Connection) SendMessage ¶
func (c *Connection) SendMessage(messageType int, data []byte) error
SendMessage 发送消息
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler WebSocket 消息处理器
func NewHandler ¶
func NewHandler(messageBus *bus.MessageBus, sessionMgr *session.Manager, channelMgr *channels.Manager) *Handler
NewHandler 创建处理器
func (*Handler) BroadcastNotification ¶
BroadcastNotification 广播通知
func (*Handler) HandleRequest ¶
func (h *Handler) HandleRequest(sessionID string, req *JSONRPCRequest) *JSONRPCResponse
HandleRequest 处理请求
type JSONRPCRequest ¶
type JSONRPCRequest struct {
JSONRPC string `json:"jsonrpc"`
ID string `json:"id,omitempty"` // 通知可以没有ID
Method string `json:"method"`
Params map[string]interface{} `json:"params,omitempty"`
}
JSONRPCRequest JSON-RPC 请求
type JSONRPCResponse ¶
type JSONRPCResponse struct {
JSONRPC string `json:"jsonrpc"`
ID string `json:"id,omitempty"`
Result interface{} `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
}
JSONRPCResponse JSON-RPC 响应
func NewErrorResponse ¶
func NewErrorResponse(id string, code int, message string) *JSONRPCResponse
NewErrorResponse 创建错误响应
func NewSuccessResponse ¶
func NewSuccessResponse(id string, result interface{}) *JSONRPCResponse
NewSuccessResponse 创建成功响应
type MessageType ¶
type MessageType string
MessageType 消息类型
const ( // Request 请求 MessageTypeRequest MessageType = "request" // Response 响应 MessageTypeResponse MessageType = "response" // Notification 通知 MessageTypeNotification MessageType = "notification" )
type MethodHandler ¶
MethodHandler 方法处理器
type MethodRegistry ¶
type MethodRegistry struct {
// contains filtered or unexported fields
}
MethodRegistry 方法注册表
func (*MethodRegistry) Call ¶
func (r *MethodRegistry) Call(method string, sessionID string, params map[string]interface{}) (interface{}, error)
Call 调用方法
func (*MethodRegistry) Register ¶
func (r *MethodRegistry) Register(method string, handler MethodHandler)
Register 注册方法
type RPCError ¶
type RPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data string `json:"data,omitempty"`
}
RPCError RPC 错误
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server HTTP 网关服务器
func NewServer ¶
func NewServer(cfg *config.GatewayConfig, messageBus *bus.MessageBus, channelMgr *channels.Manager, sessionMgr *session.Manager) *Server
NewServer 创建网关服务器
func (*Server) SetWebSocketConfig ¶
func (s *Server) SetWebSocketConfig(cfg *WebSocketConfig)
SetWebSocketConfig 设置 WebSocket 配置
type WebSocketConfig ¶
type WebSocketConfig struct {
Host string
Port int
Path string
EnableAuth bool
AuthToken string
PingInterval time.Duration
PongTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
MaxMessageSize int64
// TLS 配置
EnableTLS bool
CertFile string
KeyFile string
}
WebSocketConfig WebSocket 配置
Click to show internal directories.
Click to hide internal directories.