jsonrpc2ws

package
v0.0.0-...-66cb45a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2021 License: MIT Imports: 6 Imported by: 2

README

jsonrpc2 - ws

jsonrpc2 on websocket

use github.com/gorilla/websocket as the backend

Documentation

Overview

Package jsonrpc2ws provides websocket implement of jsonrpc2(https://godoc.org/github.com/c0mm4nd/go-jsonrpc2), the fast jsonrpc 2.0 message encoding and decoding Visit repo https://godoc.org/github.com/c0mm4nd/go-jsonrpc2 and get example

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*websocket.Conn
	ClientConfig
}

func NewClient

func NewClient(config ClientConfig) (*Client, error)

func (*Client) ReadMessage

func (c *Client) ReadMessage() (messageType int, message *jsonrpc2.JsonRpcMessage, err error)

func (*Client) ReadMessageBatch

func (c *Client) ReadMessageBatch() (messageType int, message *jsonrpc2.JsonRpcMessageBatch, err error)

func (*Client) ReadRawMessage

func (c *Client) ReadRawMessage() (messageType int, message []byte, err error)

func (*Client) WriteMessage

func (c *Client) WriteMessage(messageType int, message *jsonrpc2.JsonRpcMessage) error

type ClientConfig

type ClientConfig struct {
	Addr string
	Path string
}

type HandlerConfig

type HandlerConfig struct {
	Logger     Logger
	HandlerMap map[string]StatefulJsonRpcHandler
}

type Logger

type Logger interface {
	Debug(...interface{})
	Error(...interface{})
}

type Server

type Server struct {
	*http.Server
	*WSHandler
	// contains filtered or unexported fields
}

func NewServer

func NewServer(config ServerConfig) (*Server, error)

func WrapHTTP

func WrapHTTP(httpServer *http.Server, config ServerConfig) (*Server, error)

type ServerConfig

type ServerConfig struct {
	Addr string
	Path string

	Handler *WSHandler
	Logger  Logger
}

type SimpleLogger

type SimpleLogger struct{}

func (*SimpleLogger) Debug

func (logger *SimpleLogger) Debug(args ...interface{})

func (*SimpleLogger) Error

func (logger *SimpleLogger) Error(args ...interface{})

type StatefulJsonRpcHandler

type StatefulJsonRpcHandler interface {
	Handle(*websocket.Conn, *jsonrpc2.JsonRpcMessage) *jsonrpc2.JsonRpcMessage
}

type WSHandler

type WSHandler struct {
	HandlerConfig
	// contains filtered or unexported fields
}

WSHandler is acting as a http.Handler and will redirect the jsonrpc message to one of the registered jsonrpc handlers on its handler table

func NewWSHandler

func NewWSHandler(config HandlerConfig) *WSHandler

func (*WSHandler) RegisterJsonRpcHandleFunc

func (h *WSHandler) RegisterJsonRpcHandleFunc(method string, fn func(*websocket.Conn, *jsonrpc2.JsonRpcMessage) *jsonrpc2.JsonRpcMessage)

func (*WSHandler) RegisterJsonRpcHandler

func (h *WSHandler) RegisterJsonRpcHandler(method string, handler StatefulJsonRpcHandler)

func (*WSHandler) ServeHTTP

func (h *WSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP = ServeWS

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL