Documentation ¶
Overview ¶
Package rpc support json-rpc
Index ¶
Constants ¶
const ( // JSONRPCVER const version code of JSONRPC JSONRPCVER = "2.0" // MaxMultiRequest count MaxMultiRequest = 10 // ParseErr -32700 语法解析错误,服务端接收到无效的json。该错误发送于服务器尝试解析json文本 ParseErr = -32700 // InvalidRequest -32600 无效请求发送的json不是一个有效的请求对象。 InvalidRequest = -32600 // MethodNotFound -32601 找不到方法 该方法不存在或无效 MethodNotFound = -32601 // InvalidParamErr -32602 无效的参数 无效的方法参数。 InvalidParamErr = -32602 // InternalErr -32603 内部错误 JSON-RPC内部错误。 InternalErr = -32603 // ServerErr -32000 to -32099 Server error服务端错误, 预留用于自定义的服务器错误。 ServerErr = -32000 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is json-rpc Client includes conn field
type JsonrpcErr ¶
type JsonrpcErr struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data"` }
JsonrpcErr while dealing with rpc request got err, must return this.
func NewJsonrpcErr ¶
func NewJsonrpcErr(code int, message string, data interface{}) *JsonrpcErr
NewJsonrpcErr ...
func (*JsonrpcErr) Error ¶
func (j *JsonrpcErr) Error() string
type Request ¶
type Request struct { ID string `json:"id"` Method string `json:"method"` Params interface{} `json:"params"` Jsonrpc string `json:"jsonrpc"` }
Request Client send request to server, and server also parse request into this
func NewRequest ¶
NewRequest ...
type Response ¶
type Response struct { ID string `json:"id"` Error *JsonrpcErr `json:"error"` Result interface{} `json:"result"` Jsonrpc string `json:"jsonrpc"` }
Response is server send a response to client, and client parse to this
func NewResponse ¶
func NewResponse(id string, result interface{}, err *JsonrpcErr) *Response
NewResponse ...
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server ...
func NewServer ¶
func NewServer() *Server
NewServer want to save 'Type.Method' as key, `Method(Func type)` as value type MethodMap map[string]*service
func (*Server) Register ¶
Register parse register type and method maybe save into a Map, input value is a varible want to got varible type name, and all Method Name
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
Handle Request over HTTP Inspired by `https://github.com/gorilla/rpc`