tcp

package
v0.0.0-...-780cc0d Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultErrorConnMaxEncoder

func DefaultErrorConnMaxEncoder(writer io.Writer) error

DefaultErrorConnMaxEncoder 链接数超了

Types

type Client

type Client struct {
	Config ClientConfig
	Nacos  *nacos.Nacos
	// contains filtered or unexported fields
}

func NewClient

func NewClient(host, port string) *Client

NewClient tcp的客户端

func NewClientByServerName

func NewClientByServerName(n *nacos.Nacos, serverName string) *Client

NewClientByServerName tcp的客户端

func (*Client) Close

func (c *Client) Close()

Close 断开连接

func (*Client) Do

func (c *Client) Do(req Request) (res Response, err error)

Do 请求运行

func (*Client) Run

func (c *Client) Run() error

Run 运行

type ClientConfig

type ClientConfig struct {
	ServerName string `mapstructure:"serverName"`
	Host       string `mapstructure:"host"`
	Port       string `mapstructure:"port"`
	Timeout    int64  `mapstructure:"timeout"`
}

type Conn

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

func NewConn

func NewConn(c net.Conn, s *Server) *Conn

func (Conn) Run

func (c Conn) Run()

type Handler

type Handler interface {
	Serve(ctx context.Context, r Request) (w Response, err error)
}

type Request

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

type Response

type Response struct {
	Id      string `json:"id"`
	Success bool   `json:"success"`
	Code    int    `json:"code"`
	Message string `json:"message,omitempty"`
	Data    any    `json:"datas,omitempty"`
}

func DefaultErrorResponseMsg

func DefaultErrorResponseMsg(msg string) Response

DefaultErrorResponseMsg 根据错误信息返回

type Server

type Server struct {
	Config  ServerConfig
	Handler Handler

	Limiter *limiter.Limiter
	Nacos   *nacos.Nacos
	// contains filtered or unexported fields
}

func NewServer

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

NewServer tcp的服务端

func (*Server) Close

func (s *Server) Close()

Close 关闭服务和所有连接

func (*Server) Run

func (s *Server) Run() error

Run 运行服务

type ServerConfig

type ServerConfig struct {
	Name     string `mapstructure:"name"`
	Host     string `mapstructure:"host"`
	Port     string `mapstructure:"port"`
	Timeout  int64  `mapstructure:"timeout"`
	MaxPool  int64  `mapstructure:"maxPool"`
	Metadata map[string]string
}

Jump to

Keyboard shortcuts

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