jsonrpc2

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(id RequestId, v Result, e *Error) ([]byte, error)

Types

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data"`
}

func NewAppError

func NewAppError(
	code int,
	message string,
	data interface{},
) *Error

func NewServerError

func NewServerError(
	code int,
	data interface{},
) *Error

type JsonRpcResponse

type JsonRpcResponse struct {
	Id     RequestId
	Result *Result
	Error  *Error
}

type JsonRpcRouter

type JsonRpcRouter interface {
	/// SetRequestHandler sets a handler for a request that would return a response
	SetRequestHandler(request Request, handler func(req Request) (Result, *Error))

	/// SetNotificationHandler sets a handler for a notification, that would not return any response
	SetNotificationHandler(request Request, handler func(req Request))

	/// Handle processes incoming JSON-RPC request and either returns JSON-RPC result or error within response
	/// or returns nil if successfully processed notification
	Handle(b []byte) *JsonRpcResponse
}

func NewJsonRPCRouter

func NewJsonRPCRouter() JsonRpcRouter

type Request

type Request interface {
	GetMethod() string
}

type RequestId

type RequestId struct {
	IdString    string
	IdNumber    int
	IdIsNum     bool
	IdIsNull    bool
	IdIsMissing bool
}

func NewIntRequestId

func NewIntRequestId(id int) RequestId

func NewMissingRequestId

func NewMissingRequestId() RequestId

func NewNullRequestId

func NewNullRequestId() RequestId

func NewStringRequestId

func NewStringRequestId(id string) RequestId

func (RequestId) MarshalJSON

func (r RequestId) MarshalJSON() ([]byte, error)

type Result

type Result any

Jump to

Keyboard shortcuts

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