gojsonrpc2server

package module
v0.0.0-...-76e4069 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2021 License: GPL-3.0 Imports: 16 Imported by: 0

README

simple jsonrpc2 server for tcp and websocket

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseParameters

func ParseParameters(
	responder *HandleResponder,
	params *json.RawMessage,
	v interface{},
) (
	cancel_processing bool,
	paniced bool,
)

responder - can be nil - so will not be used

Types

type AppContextSession

type AppContextSession interface {
	RPCHandle(*RPCHandleContext)
	Destroy()
}

type Destructable

type Destructable interface {
	Destroy()
}

type HandleResponder

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

func NewHandleResponder

func NewHandleResponder(
	ctx context.Context,
	conn *jsonrpc2.Conn,
	req *jsonrpc2.Request,
	uuid string,
	log func(txt ...interface{}),
) *HandleResponder

func (*HandleResponder) Defer

func (self *HandleResponder) Defer() error

call this with defer

func (*HandleResponder) Log

func (self *HandleResponder) Log(txt ...interface{})

Format message and send it using log()

func (*HandleResponder) LogRespError

func (self *HandleResponder) LogRespError(code int64, txt ...interface{}) error

Format message, log it with log() and send copy as error reply to rpc

func (*HandleResponder) Reply

func (self *HandleResponder) Reply(result interface{}) error

Send success reply to rpc

func (*HandleResponder) ReplyWithError

func (self *HandleResponder) ReplyWithError(respErr *jsonrpc2.Error) error

Send error reply to rpc

func (*HandleResponder) RespError

func (self *HandleResponder) RespError(code int64, txt ...interface{}) error

Format text, make error message and use ReplyWithError() function

type MyHttpHandler

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

func (*MyHttpHandler) ServeHTTP

func (self *MyHttpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RPCHandleContext

type RPCHandleContext struct {
	Ctx     context.Context
	Server  *Server
	Session *Session
	// AppContext        AppContext
	AppContextSession AppContextSession
	Conn              *jsonrpc2.Conn
	Req               *jsonrpc2.Request
}

type Server

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

func NewServer

func NewServer(opts *ServerOptions) (*Server, error)

func (*Server) Destroy

func (self *Server) Destroy()

func (*Server) GetWorker

func (self *Server) GetWorker() worker.WorkerI

func (*Server) Log

func (self *Server) Log(txt ...interface{})

type ServerOptions

type ServerOptions struct {
	// Verbose bool
	Debug bool

	ListenAtAddresses    string
	ListenAtAddressesWS  string
	AsyncRequestHandling bool

	// AppContext AppContext
	CreateAppContextSession func(Destructable) (AppContextSession, error)
	EnableTLS               bool
	TLSConfig               *tls.Config

	HostStaticDir          bool
	StaticDir              string
	StaticDirURIPathPrefix string
}

type Session

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

func NewSession

func NewSession(options *SessionOptions) (*Session, error)

func (*Session) Destroy

func (self *Session) Destroy()

func (*Session) GetSessionId

func (self *Session) GetSessionId() string

func (*Session) Handle

func (self *Session) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request)

func (*Session) HandleBS

func (self *Session) HandleBS(bs jsonrpc2.ObjectStream)

func (*Session) HandleConnection

func (self *Session) HandleConnection(conn net.Conn)

func (*Session) Log

func (self *Session) Log(txt ...interface{})

type SessionOptions

type SessionOptions struct {
	Server    *Server
	SessionID string
}

type SubscriptionMgr

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

func NewSubscriptionMgr

func NewSubscriptionMgr(options *SubscriptionMgrOptions) *SubscriptionMgr

func (*SubscriptionMgr) Log

func (self *SubscriptionMgr) Log(txt ...interface{})

func (*SubscriptionMgr) Subscribe

func (self *SubscriptionMgr) Subscribe(
	remote_subscribe_command_parameter interface{},
) (descriptor string, unsubscribing_descriptor string, err error)

func (*SubscriptionMgr) Subscriptions

func (self *SubscriptionMgr) Subscriptions(descriptor string) (unsubscribing_descriptors []string, err error)

func (*SubscriptionMgr) Unsubscribe

func (self *SubscriptionMgr) Unsubscribe(descriptor string, unsubscribing_descriptor string)

func (*SubscriptionMgr) UnsubscribeAllDescriptors

func (self *SubscriptionMgr) UnsubscribeAllDescriptors(unsubscribing_descriptor string)

func (*SubscriptionMgr) UnsubscribeEverything

func (self *SubscriptionMgr) UnsubscribeEverything()

type SubscriptionMgrOptions

type SubscriptionMgrOptions struct {
	// Context          *Context
	UseAsyncHandler  bool
	GetNewConnection func() (net.Conn, error)
	Authenticator    func(conn *jsonrpc2.Conn) error
	// RemoteSubscribtionsCommand string // TODO: really needed?
	RemoteSubscribeCommand string

	GetDescriptorForParameter func(parameter interface{}) string
	RespHandler               func(
		descriptor string,
		unsubscribing_descriptor string,
		request *jsonrpc2.Request,
		uuid_str string,
	)
}

type SubscriptionMgrSession

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

func NewSubscriptionMgrSession

func NewSubscriptionMgrSession(
	mgr *SubscriptionMgr,
	descriptor string,
	parameters interface{},
) (*SubscriptionMgrSession, error)

func (*SubscriptionMgrSession) Destroy

func (self *SubscriptionMgrSession) Destroy()

func (*SubscriptionMgrSession) Handle

func (self *SubscriptionMgrSession) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request)

Jump to

Keyboard shortcuts

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