Documentation ¶
Index ¶
- Constants
- Variables
- type Call
- type Codec
- type ExtendedMethod
- type Protocol
- func (s *Protocol) Call(serviceMethod string, args interface{}, reply interface{}) error
- func (s *Protocol) Close() error
- func (s *Protocol) Go(serviceMethod string, args interface{}, reply interface{}, done chan *Call) *Call
- func (p *Protocol) Register(rcvr interface{}) error
- func (p *Protocol) RegisterName(name string, rcvr interface{}) error
- func (p *Protocol) Serve()
- type RepReq
- type ServerError
Constants ¶
const ( REQUEST = 1 RESPONSE = 2 )
Variables ¶
var ErrShutdown = errors.New("connection is shut down")
Functions ¶
This section is empty.
Types ¶
type Call ¶
type Call struct { ServiceMethod string // The name of the service and method to 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. }
Call represents an active RPC.
type Codec ¶
type Codec interface { ReadHeader(*RepReq) error ReadBody(interface{}) error Write(*RepReq, interface{}) error Close() error }
A Codec implements reading of RPC requests and writing of RPC responses for the server side of an RPC session. The server calls ReadHeader and ReadBody in pairs to read requests from the connection, and it calls Write to write a response back. The server calls Close when finished with the connection. ReadBody may be called with a nil argument to force the body of the request to be read and discarded.
type ExtendedMethod ¶
type ExtendedMethod interface {
SetProtocol(*Protocol)
}
type Protocol ¶
type Protocol struct {
// contains filtered or unexported fields
}
Protocol represents an RPC Protocol.
func NewClientWithCodec ¶
NewClientWithCodec uses the specified codec to encode requests and decode responses.
func (*Protocol) Call ¶
Call invokes the named function, waits for it to complete, and returns its error status.
func (*Protocol) Go ¶
func (s *Protocol) Go(serviceMethod string, args interface{}, reply interface{}, done chan *Call) *Call
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 (*Protocol) Register ¶
Register publishes in the server the set of methods of the receiver value that satisfy the following conditions:
- exported method
- two arguments, both pointers to exported structs
- one return value, of type error
It returns an error if the receiver is not an exported type or has no methods or unsuitable methods. It also logs the error using package log. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.
func (*Protocol) RegisterName ¶
RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.
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