Documentation ¶
Index ¶
- Constants
- Variables
- func Accept(lis net.Listener)
- func HandleHTTP()
- func Register(rcvr any) error
- type Call
- type Client
- func Dial(network, address string, opt *Option) (c *Client, err error)
- func DialHTTP(network, address string, opt *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, opt *Option) (*Client, error)
- type Option
- type Server
Constants ¶
View Source
const MagicNumber = 0x3bef5c
MagicNumber 魔数
Variables ¶
View Source
var DefaultOption = &Option{ MagicNumber: MagicNumber, CodecType: codec.GobType, ConnectTimeout: time.Second * 10, }
DefaultOption 默认协商信息
View Source
var DefaultServer = NewServer()
DefaultServer 默认服务器实例
View Source
var ErrShutdown = errors.New("connection is shutdown")
Functions ¶
func HandleHTTP ¶
func HandleHTTP()
Types ¶
type Call ¶
type Call struct { Seq int ServiceMethod string Args any Reply any Error error Done chan *Call // 结束调用时,通过这个通道通知调用方 }
Call 代表一次RPC调度
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client RPC客户端
func NewHTTPClient ¶
NewHTTPClient 通过HTTP进行建立连接
type Option ¶
type Option struct { MagicNumber int CodecType codec.Type ConnectTimeout time.Duration // 连接超时 HandleTimeout time.Duration // 处理超时 }
Option 协商信息,协商协议类型 | Option{MagicNumber: xxx, CodecType: xxx} | Header{ServiceMethod ...} | Body interface{} | | <------ 固定 JSON 编码 ------> | <------- 编码方式由 CodeType 决定 ------->|
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server RPC服务器
func (*Server) HandleHTTP ¶
func (s *Server) HandleHTTP()
Click to show internal directories.
Click to hide internal directories.