Documentation ¶
Index ¶
- Variables
- func Accept(lis net.Listener)
- func Register(rcvr interface{}) error
- func RegisterName(name string, rcvr interface{}) error
- func ServeConn(conn net.Conn)
- type Auth
- type Call
- type Client
- type Client2
- type ClientConfig
- type Interceptor
- type Request
- type Response
- type Server
- type ServerConfig
- type ServerError
- type TraceInfo
Constants ¶
This section is empty.
Variables ¶
var ( // ErrShutdown shutdown error. ErrShutdown = errors.New("connection is shut down") // ErrNoClient current no rpc client. ErrNoClient = errors.New("no rpc client") )
var DefaultServer = newServer()
DefaultServer is the default instance of *Server.
Functions ¶
func Accept ¶
Accept accepts connections on the listener and serves requests to DefaultServer for each incoming connection. Accept blocks; the caller typically invokes it in a go statement.
func Register ¶
func Register(rcvr interface{}) error
Register publishes the receiver's methods in the DefaultServer.
func RegisterName ¶
RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.
func ServeConn ¶
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 { 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). Trace trace.Trace Color string RemoteIP string Timeout time.Duration Error error // After completion, the error status. Done chan *Call // Strobes when call is complete. }
Call represents an active RPC.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wrapper is a client holder with implements pinger.
type Client2 ¶
type Client2 struct {
// contains filtered or unexported fields
}
Client2 support for load balancing and service discovery.
func NewDiscoveryCli ¶
func NewDiscoveryCli(appID string, cf *ClientConfig) (c *Client2)
NewDiscoveryCli new discovery client.
type ClientConfig ¶
type ClientConfig struct { Policy string Zone string Cluster string Color string Timeout xtime.Duration Breaker *breaker.Config }
ClientConfig rpc client config.
type Interceptor ¶
type Interceptor interface { Rate(context.Context) error Stat(context.Context, interface{}, error) Auth(context.Context, net.Addr, string) error // ip, token }
Interceptor interface.
type Request ¶
type Request struct { Color string // color RemoteIP string // remoteIP Timeout time.Duration // timeout ServiceMethod string // format: "Service.Method" Seq uint64 // sequence number chosen by client Trace TraceInfo // trace info // 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 { ServiceMethod string // echoes that of the Request Seq uint64 // echoes that of the request Error string // error, if any. }
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 { Interceptor Interceptor //拦截器 // contains filtered or unexported fields }
Server represents an RPC Server.
func (*Server) Accept ¶
Accept accepts connections on the listener and serves requests for each incoming connection. Accept blocks until the listener returns a non-nil error. The caller typically invokes Accept in a go statement.
func (*Server) Register ¶
Register publishes in the server the set of methods of the receiver value that satisfy the following conditions:
- exported method of exported type
- two arguments, both of exported type
- the second argument is a pointer
- one return value, of type error
It returns an error if the receiver is not an exported type or has no suitable 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 (*Server) RegisterName ¶
RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.
func (*Server) ServeConn ¶
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 ServerConfig ¶
ServerConfig rpc server settings.
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
Directories ¶
Path | Synopsis |
---|---|
test
Package liverpc .
|
Package liverpc . |
benchmark/bench/proto
Package grpc is a generated protocol buffer package.
|
Package grpc is a generated protocol buffer package. |
proto/testproto
Package testproto is a generated protocol buffer package.
|
Package testproto is a generated protocol buffer package. |