Documentation ¶
Index ¶
- Constants
- Variables
- type Call
- type Client
- func Dial(network, address string, opts ...*Option) (client *Client, err error)
- func DialHTTP(network, address string, opts ...*Option) (client *Client, err error)
- func DialRPC(rpcAddr string, opts ...*Option) (*Client, error)
- func NewClient(conn net.Conn, option *Option) (*Client, error)
- func NewHTTPClient(conn net.Conn, option *Option) (*Client, error)
- type DefaultDiscovery
- type Discovery
- type Option
- type RegistryDiscovery
- type Server
- func (s *Server) Accept(listener net.Listener)
- func (s *Server) HandleCodec(cc codec.Codec, rawProtocol protocol.Protocol)
- func (s *Server) HandleConn(conn io.ReadWriteCloser)
- func (s *Server) HandleHTTP()
- func (s *Server) Register(instance interface{}) error
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type StrategyMode
- type XZClient
Constants ¶
View Source
const ( RandomStrategy = iota // 随机策略 RoundRobinStrategy // 轮询 )
View Source
const Magic = 0x9f9f
Variables ¶
View Source
var DefaultOption = Option{ Magic: Magic, CodecType: codec.GobType, ConnectTimeOut: 0, }
View Source
var EmptyData = struct{}{}
Functions ¶
This section is empty.
Types ¶
type Call ¶
type Call struct { Seq uint64 ServiceMethod string // 服务名.方法名 Args interface{} Reply interface{} Error error Done chan *Call }
看下net/rpc,简直一模一样
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client xzrpc client
func NewHTTPClient ¶
NewHTTPClient 使用HTTP创建一个client实例 CONNECT localhost:8081/_xzrpc_ http/1.0 HTTP/1.0 200 Connected to xzrpc 通过HTTP CONNECT请求建立连接之后,后续的通信都交给xzrpc.Client
func (*Client) CheckAvailable ¶
type DefaultDiscovery ¶
type DefaultDiscovery struct {
// contains filtered or unexported fields
}
DefaultDiscovery 一个Discovery示例
func NewDefaultDiscovery ¶
func NewDefaultDiscovery(servers []string) *DefaultDiscovery
func (*DefaultDiscovery) Get ¶
func (d *DefaultDiscovery) Get(strategy StrategyMode) (string, error)
Get 根据策略,选择对应的服务 保证线程安全,感觉不需要整个方法加锁
func (*DefaultDiscovery) GetAll ¶
func (d *DefaultDiscovery) GetAll() ([]string, error)
GetAll 返回所有的服务
func (*DefaultDiscovery) Refresh ¶
func (d *DefaultDiscovery) Refresh() error
func (*DefaultDiscovery) Update ¶
func (d *DefaultDiscovery) Update(servers []string) error
type RegistryDiscovery ¶
type RegistryDiscovery struct { *DefaultDiscovery // contains filtered or unexported fields }
func NewRegistryDiscovery ¶
func NewRegistryDiscovery(registryAddr string, timeout time.Duration) *RegistryDiscovery
func (*RegistryDiscovery) Get ¶
func (rd *RegistryDiscovery) Get(strategy StrategyMode) (string, error)
func (*RegistryDiscovery) GetAll ¶
func (rd *RegistryDiscovery) GetAll() ([]string, error)
func (*RegistryDiscovery) Refresh ¶
func (rd *RegistryDiscovery) Refresh() error
func (*RegistryDiscovery) Update ¶
func (rd *RegistryDiscovery) Update(servers []string) error
TODO 是不是应该也支持一个?好像没必要!
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) HandleCodec ¶
根据编解码器处理数据 并发处理请求,有序返回数据
func (*Server) HandleConn ¶
func (s *Server) HandleConn(conn io.ReadWriteCloser)
首先使用 json.NewDecoder 反序列化得到 Option 实例,检查 MagicNumber 和 CodeType 的值是否正确。 然后根据 CodeType 得到对应的消息编解码器,接下来的处理交给 serverCodec。
func (*Server) HandleHTTP ¶
func (s *Server) HandleHTTP()
type StrategyMode ¶
type StrategyMode int
type XZClient ¶
type XZClient struct {
// contains filtered or unexported fields
}
XZClient 支持负载均衡的client 1. 需要服务发现实例;2. 负载均衡策略;3. 协议选择
func NewXZClient ¶
func NewXZClient(d Discovery, strategy StrategyMode, option *Option) *XZClient
func (*XZClient) Broadcast ¶
func (xzc *XZClient) Broadcast(ctx context.Context, serviceMethod string, args, reply interface{}) error
TODO 将请求广播到所有的服务实例
Source Files ¶
Click to show internal directories.
Click to hide internal directories.