Documentation ¶
Index ¶
- Constants
- Variables
- func Accept(lis net.Listener)
- func HandleHTTP()
- func Register(rcvr interface{}) error
- type Call
- type Client
- func Dial(network, addr string, opts ...*Option) (client *Client, err error)
- func DialHTTP(network, addr string, opts ...*Option) (*Client, error)
- func NewClient(conn net.Conn, opt *Option) (*Client, error)
- func NewHTTPClient(conn net.Conn, opt *Option) (*Client, error)
- func XDial(rpcAddr string, opts ...*Option) (*Client, error)
- type Option
- type Server
- func (server *Server) Accept(lis net.Listener)
- func (server *Server) HandleHTTP()
- func (server *Server) Register(rcvr interface{}) error
- func (server *Server) ServeCodec(cc codec.Codec, timeout time.Duration)
- func (server *Server) ServeConn(conn io.ReadWriteCloser)
- func (server *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
Constants ¶
const (
MagicNumber = 0x3bef5c
)
Variables ¶
var DefaultOption = &Option{ MagicNumber: MagicNumber, CodecType: codec.GobType, ConnectTimeout: time.Second * 10, }
var DefaultServer = NewServer()
DefaultServer is the default instance of *Server.
var ErrShutdown = errors.New("connection is shut down")
Functions ¶
func Accept ¶
Accept accepts connections on the listener and serves requests for each incoming connection.
func HandleHTTP ¶
func HandleHTTP()
HandleHTTP is a convenient approach for default server to register HTTP handlers
Types ¶
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 NewHTTPClient ¶
NewHTTPClient new a Client instance via HTTP as transport protocol
func XDial ¶
XDial calls different functions to connect to a RPC server according the first parameter rpcAddr. rpcAddr is a general format (protocol@addr) to represent a rpc server eg, http@10.0.0.1:7001, tcp@10.0.0.1:9999, unix@/tmp/drpc.sock
func (*Client) Call ¶
Call 是客户端暴露给用户的RPC服务调用接口,它是对 Go 的封装。 阻塞等待call.Done(),等待响应返回,是一个同步接口 Client.Call 的超时处理机制,使用 context 包实现,控制权交给用户,控制更为灵活。
func (*Client) IsAvailable ¶
IsAvailable determine whether the Client is reachable
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents an RPC Server.
func (*Server) HandleHTTP ¶
func (server *Server) HandleHTTP()
HandleHTTP registers an HTTP handler for RPC messages on defaultRPCPath. It is still necessary to invoke http.Serve(), typically in a go statement.
func (*Server) ServeConn ¶
func (server *Server) ServeConn(conn io.ReadWriteCloser)