Documentation
¶
Overview ¶
Package jsonrpc 实现简单的 JSON RPC 2.0
Index ¶
Constants ¶
View Source
const ( CodeParseError = -32700 CodeInvalidRequest = -32600 CodeMethodNotFound = -32601 CodeInvalidParams = -32602 CodeInternalError = -32603 CodeServerErrorStart = -32099 CodeServerErrorEnd = -32000 CodeServerNotInitialized = -32002 CodeUnknownErrorCode = -32001 )
JSON RPC 2.0 定义的错误代码
View Source
const Version = "2.0"
Version JSON RPC 的版本
Variables ¶
View Source
var ( ErrInvalidContentType = errors.New("无效的报头 Content-Type") ErrMissContentLength = errors.New("缺少 Content-Length 报头") )
一些错误定义
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn JSON RPC 连接对象
json-rpc 客户端和服务端是对等的,两者都使用 conn 初始化。
type Error ¶
type Error struct { // 错误代码 Code int `json:"code"` // 错误的简短描述 Message string `json:"message"` // 详细的错误描述信息,可以为空 Data interface{} `json:"data,omitempty"` }
Error JSON-RPC 返回的错误类型
func NewErrorWithData ¶
NewErrorWithData 新的 Error 对象
type HTTPConn ¶ added in v0.5.0
type HTTPConn struct {
// contains filtered or unexported fields
}
HTTPConn 表示 json rpc 的 HTTP 服务端中间件
type Server ¶ added in v0.5.0
type Server struct {
// contains filtered or unexported fields
}
Server JSON RPC 服务实例
func (*Server) NewConn ¶ added in v0.5.0
NewConn 创建长链接的 JSON RPC 实例
t 表示传输层的操作实例; errlog 表示在 serveHTTP 和 Serve 中部分不会中断执行的错误输出。 如果为空,则不会输出这些错误。
func (*Server) NewHTTPConn ¶ added in v0.5.0
NewHTTPConn 声明 HTTP 服务端中间件
url 表示主动请求时的 URL 地址,如果不需要,可以传递空值; errlog 表示错误日志输出通道,不需要可以为空。
type Transport ¶
type Transport interface { // 从转输层读取内容并转换成对象 v Read(v interface{}) error // 将对象 v 写入传输层 Write(v interface{}) error }
Transport 用于操作 JSON RPC 的传输层接口
func NewWebsocketTransport ¶
NewWebsocketTransport 声明基于 websocket 的 Transport 实例
Click to show internal directories.
Click to hide internal directories.