前言
前面几章我们完成了 服务端的编写 现在开始客户端编写
Client
1 | go复制代码type Client struct { |
option
1 | go复制代码type Options struct { |
具体每个链接
1 | go复制代码type Connect struct { |
初始化连接池
1 | go复制代码func initPool(c *Connect) (*connectPool, error) { |
Connect 调用具体服务
1 | go复制代码func (c *Connect) Call(ctx *light.Context, serviceMethod string, request interface{}, response interface{}) error { |
调用核心 重点
复习 s03 协议设计
1 | go复制代码/** |
注意: 每一个请求都有一个 magicNumber 都有一个请求ID
单个链接定义
1 | go复制代码type BaseClient struct { |
初始化单个链接
1 | go复制代码func newBaseClient(serverName string, options *Options) (*BaseClient, error) { |
heartBeat 心跳服务
1 | go复制代码func (b *BaseClient) heartBeat() { |
processMessageManager 返回消息的处理服务 (注意这里可以并发的来)
1 | go复制代码func (b *BaseClient) processMessageManager() { |
服务调用
1 | go复制代码func (b *BaseClient) call(ctx *light.Context, serviceMethod string, request interface{}, response interface{}, respChan chan error) (magic string, err error) { |
专栏地址: juejin.cn/column/6986…
本文转载自: 掘金