Documentation ¶
Index ¶
- Constants
- Variables
- func Register(cmd uint32, function interface{}) error
- func ServeCodec(codec ServerCodec)
- func ServeConn(conn io.ReadWriteCloser)
- type Call
- type Client
- func (client *Client) Call(cmd uint32, args interface{}, reply interface{}) error
- func (client *Client) CallWithTimeout(cmd uint32, args interface{}, reply interface{}, d time.Duration) error
- func (client *Client) Close() error
- func (client *Client) Go(cmd uint32, args interface{}, reply interface{}, done chan *Call) *Call
- func (client *Client) GoWithTimeout(cmd uint32, args interface{}, reply interface{}, done chan *Call, ...) *Call
- func (client *Client) OnNotify(cmd uint32, reply interface{})
- type ClientCodec
- type Error
- type JsonRequest
- type JsonResponse
- type PendingCall
- type Request
- type Response
- type Server
- func (server *Server) Call(pc interface{})
- func (server *Server) Register(cmd uint32, function interface{}) error
- func (server *Server) ServeCodec(ctx context.Context, codec ServerCodec)
- func (server *Server) ServeCodec2(ctx context.Context, codec ServerCodec, ch chan interface{})
- func (server *Server) ServeConn(ctx context.Context, conn io.ReadWriteCloser)
- type ServerCodec
- type ServerError
Constants ¶
const ( // Defaults used by HandleHTTP DefaultRPCPath = "/_goRPC_" DefaultDebugPath = "/debug/rpc" )
Variables ¶
var DefaultServer = NewServer()
var ErrShutdown = errors.New("connection is shut down")
var ErrTimeout = errors.New("operation is timeout")
Functions ¶
func ServeCodec ¶
func ServeCodec(codec ServerCodec)
ServeCodec is like ServeConn but uses the specified codec to decode requests and encode responses.
func ServeConn ¶
func ServeConn(conn io.ReadWriteCloser)
ServeConn runs the DefaultServer on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement. ServeConn uses the gob wire format (see package gob) on the connection. To use an alternate codec, use ServeCodec.
Types ¶
type Call ¶
type Call struct { Cmd uint32 // The name of the service and method to call. Seq uint32 // sequence of current call Args interface{} // The argument to the function (*struct). Reply interface{} // The reply from the function (*struct). Error error // After completion, the error status. Done chan *Call // Strobes when call is complete. // contains filtered or unexported fields }
Call represents an active RPC.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an RPC Client. There may be multiple outstanding Calls associated with a single Client, and a Client may be used by multiple goroutines simultaneously.
func DialHTTP ¶
DialHTTP connects to an HTTP RPC server at the specified network address listening on the default HTTP RPC path.
func DialHTTPPath ¶
DialHTTPPath connects to an HTTP RPC server at the specified network address and path.
func NewClient ¶
func NewClient(conn io.ReadWriteCloser) *Client
NewClient returns a new Client to handle requests to the set of services at the other end of the connection. It adds a buffer to the write side of the connection so the header and payload are sent as a unit.
func NewClientWithCodec ¶
func NewClientWithCodec(codec ClientCodec) *Client
NewClientWithCodec is like NewClient but uses the specified codec to encode requests and decode responses.
func (*Client) Call ¶
Call invokes the named function, waits for it to complete, and returns its error status.
func (*Client) CallWithTimeout ¶
func (client *Client) CallWithTimeout(cmd uint32, args interface{}, reply interface{}, d time.Duration) error
Call invokes the named function, waits for it to complete, and returns its error status. If timeout occurs, it returns ErrTimeout
func (*Client) Go ¶
Go invokes the function asynchronously. It returns the Call structure representing the invocation. The done channel will signal when the call is complete by returning the same Call object. If done is nil, Go will allocate a new channel. If non-nil, done must be buffered or Go will deliberately crash.
func (*Client) GoWithTimeout ¶
type ClientCodec ¶
type ClientCodec interface { // WriteRequest must be safe for concurrent use by multiple goroutines. WriteRequest(*Request, interface{}) error ReadResponseHeader(*Response) error ReadResponseBody(interface{}) error Close() error }
A ClientCodec implements writing of RPC requests and reading of RPC responses for the client side of an RPC session. The client calls WriteRequest to write a request to the connection and calls ReadResponseHeader and ReadResponseBody in pairs to read responses. The client calls Close when finished with the connection. ReadResponseBody may be called with a nil argument to force the body of the response to be read and then discarded.
type JsonRequest ¶
type JsonRequest struct { Cmd uint32 `json:"cmd"` Seq uint32 `json:"seq"` Params *json.RawMessage `json:"params"` }
type JsonResponse ¶
type PendingCall ¶
type PendingCall struct {
// contains filtered or unexported fields
}
test
func (*PendingCall) Context ¶
func (pc *PendingCall) Context() context.Context
type Request ¶
type Request struct { Cmd uint32 Seq uint32 // sequence number chosen by client // contains filtered or unexported fields }
Request is a header written before every RPC call. It is used internally but documented here as an aid to debugging, such as when analyzing network traffic.
type Response ¶
type Response struct { Cmd uint32 // echoes that of the Request Seq uint32 // echoes that of the request Error uint32 // error, if any. // contains filtered or unexported fields }
Response is a header written before every RPC return. It is used internally but documented here as an aid to debugging, such as when analyzing network traffic.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents an RPC Server.
func (*Server) ServeCodec ¶
func (server *Server) ServeCodec(ctx context.Context, codec ServerCodec)
ServeCodec is like ServeConn but uses the specified codec to decode requests and encode responses.
func (*Server) ServeCodec2 ¶
func (server *Server) ServeCodec2(ctx context.Context, codec ServerCodec, ch chan interface{})
test
func (*Server) ServeConn ¶
func (server *Server) ServeConn(ctx context.Context, conn io.ReadWriteCloser)
ServeConn runs the server on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement. ServeConn uses the gob wire format (see package gob) on the connection. To use an alternate codec, use ServeCodec.
type ServerCodec ¶
type ServerError ¶
type ServerError string
ServerError represents an error that has been returned from the remote side of the RPC connection.
func (ServerError) Error ¶
func (e ServerError) Error() string