Documentation ¶
Overview ¶
server
Index ¶
- Variables
- func Accept(lis net.Listener)
- func HandleHTTP()
- func Register(rcvr interface{}) error
- type Call
- type Client
- func Dial(network, address string, opts ...*Option) (client *Client, err error)
- func DialHTTP(network, address 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
Constants ¶
This section is empty.
Variables ¶
var DefaultOption = &Option{ CodecType: codec.GobType, ConnectTimeout: time.Second * 10, }
DefaultOption 默认option
var DefaultServer = NewServer()
DefaultServer 默认服务器对象
var ErrShutdown = errors.New("connection is shut down")
Functions ¶
func HandleHTTP ¶
func HandleHTTP()
HandleHTTP is a convenient approach for default server to register HTTP handlers
Types ¶
type Call ¶
type Call struct { Seq uint64 // 请求ID ServiceMethod string // 格式 "<service>.<method>" Args interface{} // 参数 Reply interface{} // 回复 Error error // 发送的错误 Done chan *Call // 调用完成时写值 }
Call 代表一次rpc调用的信息
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client rpc客户端,主要完成发送请求和接收返回结果
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/geerpc.sock
func (*Client) Call ¶
func (client *Client) Call(ctx context.Context, serviceMethod string, args, reply interface{}) error
Call 发起rpc调用,等待完成
type Option ¶
type Option struct { CodecType codec.Type // 数据编码类型 ConnectTimeout time.Duration HandleTimeout time.Duration }
Option 连接服务器的协商字段 连接服务器后,服务器读取出option的内容,根据option的内容处理后续的数据 | Option | Header1 | Body1 | Header2 | Body2 | ... 如上,一次tcp连接,Option协商数据内容信息,一对heade、body代表一次tpc方法调用,可以不断的发送rpc方法调用
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server 逻辑实现
func (*Server) HandleHTTP ¶
func (server *Server) HandleHTTP()
HandleHTTP registers an HTTP handler for RPC messages on rpcPath. It is still necessary to invoke http.Serve(), typically in a go statement.