ysjsonrpc

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidParamsError = NewJsonRPCError(-32700, "Invalid params")
)

Functions

This section is empty.

Types

type FuncHandler

type FuncHandler func(params interface{}) (result interface{}, err *JsonRPCError)

FuncHandler JsonRPC 处理函数类型,传入 <params> 函数需要根据自己的要求获取数据. 传出参数为 <err> 不为空时返回 error 数据, 否则返回 <result> 数据.

type JsonRPCError

type JsonRPCError struct {
	Code    int         `json:"code,omitempty"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

func NewJsonRPCError

func NewJsonRPCError(code int, message string, data ...interface{}) *JsonRPCError

type JsonRPCReq added in v0.9.0

type JsonRPCReq struct {
	internal.JsonRPCBase
	Method string      `json:"method"`
	Params interface{} `json:"params"`
}

func DefaultReq

func DefaultReq() *JsonRPCReq

func NewJsonrpcReq

func NewJsonrpcReq(json string) *JsonRPCReq

type JsonRPCRes added in v0.9.0

type JsonRPCRes struct {
	internal.JsonRPCBase
	Result interface{}   `json:"result,omitempty"`
	Error  *JsonRPCError `json:"error,omitempty"`
}

func NewJsonRPCRes

func NewJsonRPCRes(req *JsonRPCReq) *JsonRPCRes

func NewJsonRPCResWithError

func NewJsonRPCResWithError(req *JsonRPCReq, err *JsonRPCError) *JsonRPCRes

func NewJsonRPCResWithResult

func NewJsonRPCResWithResult(req *JsonRPCReq, result interface{}) *JsonRPCRes

func (*JsonRPCRes) Bytes added in v0.9.0

func (j *JsonRPCRes) Bytes() []byte

func (*JsonRPCRes) JsonStr added in v0.9.0

func (j *JsonRPCRes) JsonStr() string

type Manager

type Manager interface {

	// Register 注册处理函数
	Register(context.Context, string, FuncHandler) error

	// Call 根据 RPC 执行函数
	Call(context.Context, *JsonRPCReq) *JsonRPCRes

	// CallByString 字符串形式的 RPC 执行函数
	CallByString(context.Context, string) *JsonRPCRes

	// CallByBytes Byte 数组形式的 RPC 执行函数调用
	CallByBytes(context.Context, []byte) *JsonRPCRes

	// Run 线程形式运行的 RPC 函数, 结果会在 ResultCh 中
	Run(context.Context, *JsonRPCReq)

	// RunByString 字符串形式的运行
	RunByString(context.Context, string)

	// RunByBytes Byte 数组形式的运行
	RunByBytes(context.Context, []byte)

	// ResultCh 结果通道
	ResultCh() <-chan *JsonRPCRes
}

func Instance

func Instance(name ...string) Manager

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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