cmd

package
v1.8.20220610 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	RawMessage  = 0x01
	PingMessage = 0xf1
	PongMessage = 0xf2
)

Variables

View Source
var (
	ErrInvalidSign = errors.New("invalid sign")
)

Functions

func AddSession added in v1.6.20210427

func AddSession(s *Session)

func Bind

func Bind(h Handler, args interface{})

绑定,函数名作为消息ID 注:客户端发送的消息ID仅允许包含字母、数字

func BindWithName

func BindWithName(name string, h Handler, args interface{})

绑定 注:客户端发送的消息ID仅允许包含字母、数字

func BindWithoutQueue added in v1.6.20210429

func BindWithoutQueue(name string, h Handler, args interface{})

绑定。消息不入队列直接处理 注:客户端发送的消息ID仅允许包含字母、数字

func CountSession added in v1.7.20210716

func CountSession() int

func Encode

func Encode(name string, i interface{}) ([]byte, error)

func EncodePackage added in v1.8.20210922

func EncodePackage(pkg *Package) ([]byte, error)

func Forward

func Forward(name string, msgId string, i interface{})

消息通过router转发 name = "*":向所有非网关服务转发消息

func Handle

func Handle(ctx *Context, name string, data []byte) error

func Hook added in v1.5.20210312

func Hook(h Handler)

func ListenAndServe

func ListenAndServe(addr string) error

func RegisterService

func RegisterService(conf *ServiceConfig)

向router注册服务

func RemoveSession added in v1.6.20210427

func RemoveSession(id string)

func Request

func Request(serverName, msgId string, in interface{}) ([]byte, error)

同步请求

func RequestServerAddr

func RequestServerAddr(name string) (string, error)

向路由请求服务器地址

func Route

func Route(serverId, msgId string, i interface{})

func RunOnce

func RunOnce()

Types

type Client

type Client struct {
	*TCPConn
	// contains filtered or unexported fields
}

func (*Client) ServerId added in v1.8.20210923

func (c *Client) ServerId() string

type CmdSet

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

func (*CmdSet) Bind

func (s *CmdSet) Bind(name string, h Handler, i interface{}, isPushQueue bool)

func (*CmdSet) Handle

func (s *CmdSet) Handle(ctx *Context, msgId string, data []byte) error

func (*CmdSet) Hook added in v1.5.20210312

func (s *CmdSet) Hook(h Handler)

type Conn

type Conn interface {
	Write([]byte) error
	WriteJSON(string, interface{}) error
	RemoteAddr() string
	Close()
}

type Context

type Context struct {
	Out         Conn   // 连接
	MsgId       string // 消息ID
	Ssid        string // 发送方会话ID
	Version     int    // 协议版本,当前未生效
	ServerName  string // 请求的协议头
	ClientAddr  string // 客户端地址
	MatchServer string // 多个服务合并后的唯一serverName
	// contains filtered or unexported fields
}

func (*Context) Fail added in v1.6.20210608

func (ctx *Context) Fail()

失败后不再处理后续消息

type Handler

type Handler func(*Context, interface{})

type M added in v1.8.20210922

type M = internal.M

忽略nil类型nil/slice/pointer

type Package

type Package struct {
	Id         string          `json:",omitempty"`    // 消息ID
	Data       json.RawMessage `json:",omitempty"`    // 数据,object类型
	Sign       string          `json:",omitempty"`    // 签名
	Ssid       string          `json:",omitempty"`    // 会话ID
	Version    int             `json:"Ver,omitempty"` // 版本
	Ts         int64           `json:",omitempty"`    // 过期时间戳
	ServerName string          `json:",omitempty"`    // 请求的协议头
	ClientAddr string          `json:",omitempty"`    // 客户端地址

	Body interface{} `json:"-"` // 解析成Data
}

func Decode

func Decode(buf []byte) (*Package, error)

type ServeConn

type ServeConn struct {
	*TCPConn
	// contains filtered or unexported fields
}

type Server

type Server struct {
	Addr string
}

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

func (*Server) Serve

func (srv *Server) Serve(l net.Listener) error

type ServiceConfig

type ServiceConfig struct {
	Id        string `json:",omitempty"` // 服务ID。可为空
	Name      string `json:",omitempty"` // 服务名。存在多个时采用逗号,隔开
	Addr      string `json:",omitempty"` // 地址
	MinWeight int    `json:",omitempty"` // 最小的负载
	MaxWeight int    `json:",omitempty"` // 最大的负载
}

type Session

type Session struct {
	Id  string
	Out Conn
}

func GetSession

func GetSession(id string) *Session

func GetSessionList

func GetSessionList() []*Session

func (*Session) Route

func (ss *Session) Route(serverId, msgId string, msgData interface{})

func (*Session) ServerId added in v1.8.20210923

func (ss *Session) ServerId() string

func (*Session) WriteJSON

func (ss *Session) WriteJSON(msgId string, msgData interface{})

type TCPConn

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

func (*TCPConn) Close

func (c *TCPConn) Close()

func (*TCPConn) ReadMessage

func (c *TCPConn) ReadMessage() (uint8, []byte, error)

func (*TCPConn) RemoteAddr

func (c *TCPConn) RemoteAddr() string

func (*TCPConn) Write

func (c *TCPConn) Write(data []byte) error

func (*TCPConn) WriteJSON

func (c *TCPConn) WriteJSON(name string, i interface{}) error

Jump to

Keyboard shortcuts

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