Documentation ¶
Index ¶
- Constants
- func GetChannels() map[string]func(RequestMessage, *Client)
- func RegisterChannelHandler(channel string, fn func(RequestMessage, *Client))
- func SendMessageAndWaitForResponse(conn *websocket.Conn, req any, response chan ResponseMessage)
- func WebsocketHandler(w http.ResponseWriter, r *http.Request)
- type Client
- type ClientContext
- type ClientContextKey
- type ErrorMessage
- type ReasonMessage
- type RequestMessage
- type ResponseMessage
- type WsHandlerFunc
- type WsMiddewareFunc
Constants ¶
View Source
const ( // Parse error Invalid JSON was received by the server An error occurred on the server while parsing the JSON text. InvalidJSON int64 = -32700 // Invalid Request The JSON sent is not a valid Request object. InvalidRequest int64 = -32600 // Method not found The method does not exist / is not available. MethodNotFound int64 = -32601 // Invalid params Invalid method parameter(s). Invalidparams int64 = -32602 // Internal error Internal JSON-RPC error. InternalError int64 = -32603 // -32000 to -32099 Server error ServerError int64 = -32000 )
View Source
const ( PING = "PING" PONG = "PONG" JSONRPC = "2.0" )
Variables ¶
This section is empty.
Functions ¶
func GetChannels ¶
func GetChannels() map[string]func(RequestMessage, *Client)
func RegisterChannelHandler ¶
func RegisterChannelHandler(channel string, fn func(RequestMessage, *Client))
func SendMessageAndWaitForResponse ¶
func SendMessageAndWaitForResponse(conn *websocket.Conn, req any, response chan ResponseMessage)
func WebsocketHandler ¶
func WebsocketHandler(w http.ResponseWriter, r *http.Request)
Types ¶
type Client ¶
type Client struct { *websocket.Conn Context ClientContext // contains filtered or unexported fields }
func (*Client) Send ¶
func (c *Client) Send(message ResponseMessage)
type ClientContext ¶
func (*ClientContext) Get ¶
func (c *ClientContext) Get(key ClientContextKey) any
func (*ClientContext) GetId ¶
func (c *ClientContext) GetId() uint64
func (*ClientContext) Set ¶
func (c *ClientContext) Set(key ClientContextKey, val any)
type ClientContextKey ¶
type ClientContextKey string
const (
ClientId ClientContextKey = "ClientId"
)
type ErrorMessage ¶
type ErrorMessage struct { Message string `json:"message"` Data *ReasonMessage `json:"data"` Code int64 `json:"code"` }
type ReasonMessage ¶
type ReasonMessage struct {
Reason string `json:"reason"`
}
type RequestMessage ¶
type ResponseMessage ¶
type ResponseMessage struct { JSONRPC string `json:"jsonrpc"` ID uint64 `json:"id,omitempty"` Method string `json:"method,omitempty"` Result any `json:"result,omitempty"` Params any `json:"params,omitempty"` UsIn uint64 `json:"usIn,omitempty"` UsOut uint64 `json:"usOut,omitempty"` UsDiff uint64 `json:"usDiff,omitempty"` Error *ErrorMessage `json:"error,omitempty"` }
type WsHandlerFunc ¶
type WsHandlerFunc func(RequestMessage, *Client)
func MiddlewaresWrapper ¶
func MiddlewaresWrapper(handler WsHandlerFunc, middlewares ...WsMiddewareFunc) WsHandlerFunc
type WsMiddewareFunc ¶
type WsMiddewareFunc func(RequestMessage, *Client) *ResponseMessage
Source Files ¶
Click to show internal directories.
Click to hide internal directories.