Documentation ¶
Index ¶
Constants ¶
View Source
const ( // Success 0 . Success = 0 // 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 // ServerErr -32000 to -32099 Server error服务端错误, 预留用于自定义的服务器错误。 //认证错误 AuthCheckErr = -32000 )
View Source
const ( // OpRequest . OpRequest uint16 = iota + 1 // OpResponse . OpResponse )
View Source
const ( // Ver1 . Ver1 uint16 = 1 // Ver2 . Ver2 = 2 )
View Source
const (
// VERSIONCODE const version code of JSONRPC
VERSIONCODE = "2.0"
)
Variables ¶
View Source
var ( // ErrProtoHeaderLen . ErrProtoHeaderLen = errors.New("not matched proto header len") // ErrEmptyReader . ErrEmptyReader = errors.New("empty reader") )
View Source
var ( Request = &jsonRequest{} Response = &jsonResponse{} )
View Source
var Log *us.Logs
Functions ¶
func ReadNBytes ¶
ReadNBytes . read limitted `N` bytes from bufio.Reader.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClientWithCodec ¶
func NewClientWithCodec(codec ClientCodec, tcpAddr string) *Client
type ClientCodec ¶
type ClientCodec interface { // generate a single NewRequest with needed params NewRequest(method string, argv interface{}) jsonRequest // EncodeRequests . EncodeRequests(v interface{}) ([]byte, error) // parse encoded data into a Response ReadResponse(data []byte) ([]jsonResponse, error) // ReadResponseBody . ReadResponseBody(respBody []byte, rcvr interface{}) error }
ClientCodec .
type Proto ¶
type Proto struct { Ver uint16 Op uint16 // Type of Proto Seq uint16 // Seq of message, 0 means done, else means not finished Body []byte // Body of Proto }
Proto .
type Server ¶
type Server struct { AuthCheck *Auth //认证检测 // contains filtered or unexported fields }
Server data struct to serve RPC request over TCP and HTTP
func NewServerWithCodec ¶
func NewServerWithCodec(codec ServerCodec) *Server
type ServerCodec ¶
type ServerCodec interface { // parse encoded data into a Request ReadRequest(data []byte) ([]jsonRequest, error) // ReadRequestBody parse params ReadRequestBody(reqBody []byte, rcvr interface{}) error // generate a single Response with needed params NewResponse(replyv interface{}) jsonResponse // ErrResponse to generate a Reponse contains error ErrResponse(errcode int, err error) jsonResponse // EncodeResponses . EncodeResponses(v interface{}) ([]byte, error) }
ServerCodec . parse request and write response to client.
Click to show internal directories.
Click to hide internal directories.