jsonrpc

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package jsonrpc 实现 JSON-RPC 协议的服务端与客户端

该包包含请求/响应编解码、错误码定义与连接管理

Index

Constants

View Source
const (
	JRPCParseError     = -32700
	JRPCInvalidRequest = -32600
	JRPCMethodNotFound = -32601
	JRPCInvalidParams  = -32602
	JRPCInternalError  = -32603
	JRPCServerError    = -32099
)

Error Codes

View Source
const JSONRPCVersion = "2.0"

JSONRPCVersion JSON-RPC 版本号

Variables

This section is empty.

Functions

func Set

func Set[T any, T2 any](s *Server, method string, function func(T, func(string, any, *string) error, uint64) (T2, error))

Set 设置方法

Types

type Error

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

Error JSON-RPC 错误结构体

type IgnoreReply

type IgnoreReply struct{}

IgnoreReply 忽略回复

type Request

type Request struct {
	Version string `json:"jsonrpc"`
	ID      any    `json:"id,omitempty"`
	Method  string `json:"method"`
	Params  u.H    `json:"params"`
}

Request JSON-RPC 请求结构体

type RequestWithoutID

type RequestWithoutID struct {
	Version string `json:"jsonrpc"`
	ID      any    `json:"id,omitempty"`
	Method  string `json:"method"`
	Params  u.H    `json:"params"`
}

RequestWithoutID JSON-RPC 请求结构体

type Response

type Response struct {
	Version string `json:"jsonrpc"`
	ID      any    `json:"id,omitempty"`
	Result  any    `json:"result,omitempty"`
	Error   *Error `json:"error,omitempty"`
}

Response JSON-RPC 响应结构体

type Server

type Server struct {
	Methods map[string]func(u.H, func(string, any, *string) error, uint64) (any, error)
}

Server jsonrpc 服务器

func New

func New() *Server

New 创建一个 jsonrpc 服务器

func (*Server) Start

func (s *Server) Start()

Start 启动 jsonrpc 服务器(使用 stdio)

func (*Server) StartWs

func (s *Server) StartWs() error

StartWs 启动 WebSocket JSON-RPC 服务器

Directories

Path Synopsis
Package connect 提供 JSON-RPC 连接传输层实现
Package connect 提供 JSON-RPC 连接传输层实现

Jump to

Keyboard shortcuts

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