rpc

package
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConn

func NewConn(conn io.ReadWriteCloser) rpc.ServerCodec

Types

type Client

type Client struct {
	Config ClientConfig
	Nacos  *nacos.Nacos
}

func NewClient

func NewClient(n *nacos.Nacos) *Client

func (*Client) Do

func (c *Client) Do(ctx context.Context, serverName string, method string, req any, res any) error

type ClientConfig

type ClientConfig struct {
	Retry   int64 `mapstructure:"retry"` // 重试次数
	Timeout int64 `mapstructure:"timeout"`
}

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) ReadRequestBody

func (c *Conn) ReadRequestBody(x any) error

func (*Conn) ReadRequestHeader

func (c *Conn) ReadRequestHeader(r *rpc.Request) error

func (*Conn) WriteResponse

func (c *Conn) WriteResponse(r *rpc.Response, x any) error

type Handler

type Handler struct {
	Method   string
	Receiver any
}

type Request

type Request struct {
	Id     *json.RawMessage `json:"id"`
	Method string           `json:"method"`
	Params *json.RawMessage `json:"params"`
}

type Response

type Response struct {
	Id     *json.RawMessage
	Result any
	Error  any
}

type Server

type Server struct {
	Config   ServerConfig
	Conns    []*net.Conn
	Handlers []Handler
	Limiter  *limiter.Limiter
	Nacos    *nacos.Nacos
}

func NewServer

func NewServer(c ServerConfig, l *limiter.Limiter, n *nacos.Nacos) *Server

NewServer rpc的服务端

func (*Server) Register

func (s *Server) Register(method string, receiver any) error

func (*Server) Run

func (s *Server) Run() error

type ServerConfig

type ServerConfig struct {
	Name         string `mapstructure:"name"`
	Host         string `mapstructure:"host"`
	Port         string `mapstructure:"port"`
	ReadTimeout  int64  `mapstructure:"readTimeout"`
	WriteTimeout int64  `mapstructure:"writeTimeout"`
	Metadata     map[string]string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL