connector

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2020 License: MIT Imports: 21 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseCommands

func ParseCommands()

Types

type ChanMsgPack

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

用户 接收消息 封装 channel 传输用

type CheckOriginHFunc

type CheckOriginHFunc func(r *http.Request) bool

type Connector

type Connector struct {
	CRChan       chan *ChanMsgPack
	CWChan       chan []byte
	CRRoutineCan context.CancelFunc
	CWRoutineCan context.CancelFunc
	LinkerClient linker.ILinker
	// contains filtered or unexported fields
}

func (*Connector) AddExceptionHandler

func (c *Connector) AddExceptionHandler(handler gnError.ExceptionHandleFunc)

func (*Connector) AddRouterRearEndHandler

func (c *Connector) AddRouterRearEndHandler(serverType string, handler RouteRearEndHFunc)

func (*Connector) CMDHandler added in v0.1.4

func (c *Connector) CMDHandler(cmd string, handler gn.HandlerFunc)

func (*Connector) Done

func (c *Connector) Done()

func (*Connector) ErrorToClient

func (c *Connector) ErrorToClient(cid string, code string, errorMsg string)

func (*Connector) ExceptionHandler

func (c *Connector) ExceptionHandler(exception *gnError.GnException)

func (*Connector) GetLinker

func (c *Connector) GetLinker() linker.ILinker

func (*Connector) GetServerIdByRouter

func (c *Connector) GetServerIdByRouter(serverType string, LogicBindId string, cid string, serverList []*config.ServersConfig) string

func (*Connector) ListenAndRun

func (c *Connector) ListenAndRun() error

func (*Connector) LoopClientReadChan

func (c *Connector) LoopClientReadChan(ctx context.Context)

func (*Connector) LoopLinkerChan

func (c *Connector) LoopLinkerChan(ctx context.Context)

func (*Connector) Run

func (c *Connector) Run() error

func (*Connector) SendPack

func (c *Connector) SendPack(serverAddress, router, bindId, cid string, data []byte)

func (*Connector) SetCheckOriginHandler

func (c *Connector) SetCheckOriginHandler(handler CheckOriginHFunc)

func (*Connector) SetVerifyConnectHandler

func (c *Connector) SetVerifyConnectHandler(handler VerifyClientConnectHFunc)

type IConnection

type IConnection interface {
	SendMessage(data []byte)
	Run()
	Done()
	// for  read  or   write msg
	WriteMsg(ctx context.Context)
	ReadMsg(ctx context.Context)
	GetConnectionCid() string
	GetConnection() interface{}
	SetBindId(bindId string)
	GetBindId() string
}

client Connection interface

type IConnector

type IConnector interface {
	Run() error
	Done()
	AddRouterRearEndHandler(serverType string, handler RouteRearEndHFunc)
	// set checkOrigin 跨域 func
	SetCheckOriginHandler(handler CheckOriginHFunc)
	// set verify Connect func
	SetVerifyConnectHandler(handler VerifyClientConnectHFunc)
	AddExceptionHandler(handler gnError.ExceptionHandleFunc)

	CMDHandler(cmd string, handler gn.HandlerFunc)

	LoopClientReadChan(ctx context.Context)
	LoopLinkerChan(ctx context.Context)
	ListenAndRun() error
	GetLinker() linker.ILinker
	SendPack(serverAddress, router, bindId, cid string, data []byte)
	GetServerIdByRouter(serverType string, LogicBindId string, cid string, serverList []*config.ServersConfig) string
}

connector interface

func DefaultConnector

func DefaultConnector(config *config.Config) (IConnector, error)

type RouteRearEndHFunc

type RouteRearEndHFunc func(cid, bindId string, serverList []*config.ServersConfig) (serverId string)

type VerifyClientConnectHFunc

type VerifyClientConnectHFunc func(r *http.Request) bool

type WSConnection

type WSConnection struct {
	RChan chan []byte
	WChan chan *ChanMsgPack
	// contains filtered or unexported fields
}

func NewWSConnection

func NewWSConnection(conn *websocket.Conn, outChan chan *ChanMsgPack,
	detect *gnError.GnExceptionDetect) *WSConnection

func (*WSConnection) CloseHandler

func (wc *WSConnection) CloseHandler(code int, text string) error

func (*WSConnection) Done

func (wc *WSConnection) Done()

func (*WSConnection) GetBindId

func (wc *WSConnection) GetBindId() string

func (*WSConnection) GetConnection

func (wc *WSConnection) GetConnection() interface{}

func (*WSConnection) GetConnectionCid

func (wc *WSConnection) GetConnectionCid() string

func (*WSConnection) ReadMsg

func (wc *WSConnection) ReadMsg(ctx context.Context)

read Message from WS

func (*WSConnection) Run

func (wc *WSConnection) Run()

func (*WSConnection) SendMessage

func (wc *WSConnection) SendMessage(data []byte)

func (*WSConnection) SetBindId

func (wc *WSConnection) SetBindId(bindId string)

func (*WSConnection) WriteMsg

func (wc *WSConnection) WriteMsg(ctx context.Context)

send Message to WS

Jump to

Keyboard shortcuts

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