jsonrpc2ws

package module
v0.0.0-...-9be1d1a Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: MIT Imports: 7 Imported by: 0

README

jsonrpc2-ws

JSON-RPC 2.0 over WebSocket for Go

Usage

import (
    "github.com/ggicci/jsonrpc2-ws"
    "github.com/ggicci/jsonrpc2"
)

websocketHandler := jsonrpc2ws.NewJSONRPC2Handler()
func CloneRepo(conn *jsonrpc2.Conn, req *jsonrpc2.Request) {
    // ...
}

func DeployApp(conn *jsonrpc2.Conn, req *jsonrpc2.Request) {
    // ...
}

websocketHandler.RegisterMethod("clone", jsonrpc2.HandlerFunc(CloneRepo))
websocketHandler.RegisterMethod("deploy", jsonrpc2.HandlerFunc(DeployApp))

http.Handle("/", websocketHanler)
http.ListenAndServe(":8080", nil)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMethodAlreadyRegistered = errors.New("duplicate method name")
)

Functions

This section is empty.

Types

type JSONRPC2Handler

type JSONRPC2Handler struct {
	// contains filtered or unexported fields
}

func NewJSONRPC2Handler

func NewJSONRPC2Handler() *JSONRPC2Handler

func (*JSONRPC2Handler) Handle

func (jh *JSONRPC2Handler) Handle(conn *jsonrpc2.Conn, req *jsonrpc2.Request)

Handle implements jsonrpc2.Handler interface.

func (*JSONRPC2Handler) MustRegisterMethod

func (jh *JSONRPC2Handler) MustRegisterMethod(method string, h jsonrpc2.Handler)

func (*JSONRPC2Handler) RegisterMethod

func (jh *JSONRPC2Handler) RegisterMethod(method string, h jsonrpc2.Handler) error

func (*JSONRPC2Handler) ServeHTTP

func (jh *JSONRPC2Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler interface.

Jump to

Keyboard shortcuts

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