qim

package module
v0.0.0-...-e7f8777 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

README

Documentation

Overview

Package qim is a generated GoMock package.

Package qim is a generated GoMock package.

Package qim is a generated GoMock package.

Index

Constants

View Source
const (
	DefaultReadwait  = time.Minute * 3
	DefaultWritewait = time.Second * 10
	DefaultLoginwait = time.Second * 10
	DefaultHeartbeat = time.Second * 55
)
View Source
const (
	DefaultMessageReadPool = 5000
	DefaultConnectionPool  = 5000
)

Variables

View Source
var ErrSessionLost = errors.New("err:session lost")
View Source
var ErrSessionNil = errors.New("err:session nil")

Functions

func FromRequest

func FromRequest(r *http.Request) string

FromRequest returns the real IP address of the client. It parses the X-Forwarded-For header or the X-Real-Ip header if they are present in the request. Otherwise it returns the request.RemoteAddr. If the request is nil then it returns an empty string.

func GetLocalIP

func GetLocalIP() string

Types

type Acceptor

type Acceptor interface {
	// 返回有个握手完成的Channel对象或者一个error。
	// 业务层需要处理不同协议和网络环境下的连接握手协议。
	Accept(conn Conn, timeout time.Duration) (string, Meta, error)
}

连接接收器

type Agent

type Agent interface {
	ID() string
	Push(payload []byte) error
	GetMeta() Meta
}

type Channel

type Channel interface {
	Conn
	Agent
	Close() error
	Readloop(lst MessageListener) error
	SetWritewait(timeout time.Duration)
	SetReadwait(timeout time.Duration)
}

func NewChannel

func NewChannel(id string, meta Meta, conn Conn, gpool *ants.Pool, logger *zap.Logger) Channel

type ChannelImpl

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

websocket implementation of Channel

func (*ChannelImpl) Close

func (ch *ChannelImpl) Close() error

func (*ChannelImpl) GetMeta

func (ch *ChannelImpl) GetMeta() Meta

GetMeta implements Channel

func (*ChannelImpl) ID

func (ch *ChannelImpl) ID() string

ID implements Channel

func (*ChannelImpl) Push

func (ch *ChannelImpl) Push(payload []byte) error

Push implements Channel 异步写入消息

func (*ChannelImpl) Readloop

func (ch *ChannelImpl) Readloop(lst MessageListener) error

Readloop implements Channel 负责读取消息与心跳处理(SetReadDeadline) 利用atomic保证只被一个线程调用

func (*ChannelImpl) SetReadwait

func (ch *ChannelImpl) SetReadwait(timeout time.Duration)

SetReadwait implements Channel

func (*ChannelImpl) SetWritewait

func (ch *ChannelImpl) SetWritewait(timeout time.Duration)

SetWritewait implements Channel

type ChannelMap

type ChannelMap interface {
	// add channel
	Add(ch Channel)
	// remove channel by id
	Remove(id string)
	// get channel by id
	Get(id string) (Channel, bool)
	// return all channels
	All() []Channel
}

func NewChannels

func NewChannels(num int) ChannelMap

type ChannlesImpl

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

func (*ChannlesImpl) Add

func (cs *ChannlesImpl) Add(c Channel)

Add implements ChannelMap

func (*ChannlesImpl) All

func (cs *ChannlesImpl) All() []Channel

All implements ChannelMap

func (*ChannlesImpl) Get

func (cs *ChannlesImpl) Get(id string) (Channel, bool)

Get implements ChannelMap

func (*ChannlesImpl) Remove

func (cs *ChannlesImpl) Remove(id string)

Remove implements ChannelMap

type Client

type Client interface {
	Service
	Connect(addr string) error
	SetDialer(dialer Dialer)
	Send(payload []byte) error
	Read() (Frame, error)
	Close()
}

type Conn

type Conn interface {
	net.Conn
	ReadFrame() (Frame, error)
	WriteFrame(opcode OpCode, payload []byte) error
	Flush() error
}

type Context

type Context interface {
	Dispatcher
	SessionStorage
	Header() *pkt.Header
	ReadBody(value proto.Message) error
	Session() Session
	RespWithError(status pkt.Status, err error) error
	Resp(status pkt.Status, body proto.Message) error
	Dispatch(body proto.Message, recvs ...*Location) error
	Next()
}

func BuildContext

func BuildContext() Context

type ContextImpl

type ContextImpl struct {
	sync.Mutex
	Dispatcher
	SessionStorage
	// contains filtered or unexported fields
}

ContextImpl the most important part

func (*ContextImpl) Dispatch

func (c *ContextImpl) Dispatch(body protoreflect.ProtoMessage, recvs ...*Location) error

Dispatch implements Context

func (*ContextImpl) Header

func (c *ContextImpl) Header() *pkt.Header

Header implements Context

func (*ContextImpl) Next

func (c *ContextImpl) Next()

Next implements Context

func (*ContextImpl) ReadBody

func (c *ContextImpl) ReadBody(value protoreflect.ProtoMessage) error

ReadBody implements Context

func (*ContextImpl) Resp

func (c *ContextImpl) Resp(status pkt.Status, body protoreflect.ProtoMessage) error

Resp implements Context

func (*ContextImpl) RespWithError

func (c *ContextImpl) RespWithError(status pkt.Status, err error) error

RespWithError implements Context

func (*ContextImpl) Session

func (c *ContextImpl) Session() Session

Session implements Context

type DefaultServer

type DefaultServer struct {
	Upgrader

	ServiceRegistration
	ChannelMap
	Acceptor
	MessageListener
	StateListener
	// contains filtered or unexported fields
}

DefaultServer is a websocket implemnetation of qim.Server

func NewServer

func NewServer(
	listen string,
	service ServiceRegistration,
	upgrader Upgrader,
	options ...ServerOption,
) *DefaultServer

func (*DefaultServer) Push

func (s *DefaultServer) Push(channelID string, payload []byte) error

Push implements Server

func (*DefaultServer) SetAcceptor

func (s *DefaultServer) SetAcceptor(acceptor Acceptor)

SetAcceptor implements Server

func (*DefaultServer) SetChannelMap

func (s *DefaultServer) SetChannelMap(channelMap ChannelMap)

SetChannelMap implements Server

func (*DefaultServer) SetMessageListener

func (s *DefaultServer) SetMessageListener(messageListener MessageListener)

SetMessageListener implements Server

func (*DefaultServer) SetReadwait

func (s *DefaultServer) SetReadwait(readwait time.Duration)

SetReadwait implements Server

func (*DefaultServer) SetStateListener

func (s *DefaultServer) SetStateListener(stateListener StateListener)

SetStateListener implements Server

func (*DefaultServer) Shutdown

func (s *DefaultServer) Shutdown(ctx context.Context) error

Shutdown implements Server

func (*DefaultServer) Start

func (s *DefaultServer) Start() error

Start implements Server

type Dialer

type Dialer interface {
	DialAndHandshake(ctx DialerContext) (net.Conn, error)
}

type DialerContext

type DialerContext struct {
	ID      string
	Name    string
	Address string
	Timeout time.Duration
}

type Dispatcher

type Dispatcher interface {
	Push(gateway string, channels []string, p *pkt.LogicPkt) error
}

The Dispatcher is responsible for dispatch messages to the gateway.

type Frame

type Frame interface {
	SetOpCode(opcode OpCode)
	GetOpCode() OpCode
	SetPayload(payload []byte)
	GetPayload() []byte
}

type FuncTree

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

FuncTree is a tree structure

func NewTree

func NewTree() *FuncTree

func (*FuncTree) Add

func (t *FuncTree) Add(path string, handlers ...HandlerFunc)

func (*FuncTree) Get

func (t *FuncTree) Get(path string) (HandlersChain, bool)

type HandlerFunc

type HandlerFunc func(Context)

type HandlersChain

type HandlersChain []HandlerFunc

type Location

type Location struct {
	ChannelID string
	GateID    string
}

func (*Location) Bytes

func (loc *Location) Bytes() []byte

func (*Location) Unmarshal

func (loc *Location) Unmarshal(data []byte) (err error)

type MessageListener

type MessageListener interface {
	// 收到消息回调
	Receive(agent Agent, payload []byte)
}

监听消息

type Meta

type Meta map[string]string

type MockAcceptor

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

MockAcceptor is a mock of Acceptor interface.

func NewMockAcceptor

func NewMockAcceptor(ctrl *gomock.Controller) *MockAcceptor

NewMockAcceptor creates a new mock instance.

func (*MockAcceptor) Accept

func (m *MockAcceptor) Accept(conn Conn, timeout time.Duration) (string, Meta, error)

Accept mocks base method.

func (*MockAcceptor) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

type MockAcceptorMockRecorder

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

MockAcceptorMockRecorder is the mock recorder for MockAcceptor.

func (*MockAcceptorMockRecorder) Accept

func (mr *MockAcceptorMockRecorder) Accept(conn, timeout interface{}) *gomock.Call

Accept indicates an expected call of Accept.

type MockAgent

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

MockAgent is a mock of Agent interface.

func NewMockAgent

func NewMockAgent(ctrl *gomock.Controller) *MockAgent

NewMockAgent creates a new mock instance.

func (*MockAgent) EXPECT

func (m *MockAgent) EXPECT() *MockAgentMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockAgent) GetMeta

func (m *MockAgent) GetMeta() Meta

GetMeta mocks base method.

func (*MockAgent) ID

func (m *MockAgent) ID() string

ID mocks base method.

func (*MockAgent) Push

func (m *MockAgent) Push(payload []byte) error

Push mocks base method.

type MockAgentMockRecorder

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

MockAgentMockRecorder is the mock recorder for MockAgent.

func (*MockAgentMockRecorder) GetMeta

func (mr *MockAgentMockRecorder) GetMeta() *gomock.Call

GetMeta indicates an expected call of GetMeta.

func (*MockAgentMockRecorder) ID

func (mr *MockAgentMockRecorder) ID() *gomock.Call

ID indicates an expected call of ID.

func (*MockAgentMockRecorder) Push

func (mr *MockAgentMockRecorder) Push(payload interface{}) *gomock.Call

Push indicates an expected call of Push.

type MockChannel

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

MockChannel is a mock of Channel interface.

func NewMockChannel

func NewMockChannel(ctrl *gomock.Controller) *MockChannel

NewMockChannel creates a new mock instance.

func (*MockChannel) Close

func (m *MockChannel) Close() error

Close mocks base method.

func (*MockChannel) EXPECT

func (m *MockChannel) EXPECT() *MockChannelMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockChannel) Flush

func (m *MockChannel) Flush() error

Flush mocks base method.

func (*MockChannel) GetMeta

func (m *MockChannel) GetMeta() Meta

GetMeta mocks base method.

func (*MockChannel) ID

func (m *MockChannel) ID() string

ID mocks base method.

func (*MockChannel) LocalAddr

func (m *MockChannel) LocalAddr() net.Addr

LocalAddr mocks base method.

func (*MockChannel) Push

func (m *MockChannel) Push(payload []byte) error

Push mocks base method.

func (*MockChannel) Read

func (m *MockChannel) Read(b []byte) (int, error)

Read mocks base method.

func (*MockChannel) ReadFrame

func (m *MockChannel) ReadFrame() (Frame, error)

ReadFrame mocks base method.

func (*MockChannel) Readloop

func (m *MockChannel) Readloop(lst MessageListener) error

Readloop mocks base method.

func (*MockChannel) RemoteAddr

func (m *MockChannel) RemoteAddr() net.Addr

RemoteAddr mocks base method.

func (*MockChannel) SetDeadline

func (m *MockChannel) SetDeadline(t time.Time) error

SetDeadline mocks base method.

func (*MockChannel) SetReadDeadline

func (m *MockChannel) SetReadDeadline(t time.Time) error

SetReadDeadline mocks base method.

func (*MockChannel) SetReadwait

func (m *MockChannel) SetReadwait(timeout time.Duration)

SetReadwait mocks base method.

func (*MockChannel) SetWriteDeadline

func (m *MockChannel) SetWriteDeadline(t time.Time) error

SetWriteDeadline mocks base method.

func (*MockChannel) SetWritewait

func (m *MockChannel) SetWritewait(timeout time.Duration)

SetWritewait mocks base method.

func (*MockChannel) Write

func (m *MockChannel) Write(b []byte) (int, error)

Write mocks base method.

func (*MockChannel) WriteFrame

func (m *MockChannel) WriteFrame(opcode OpCode, payload []byte) error

WriteFrame mocks base method.

type MockChannelMockRecorder

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

MockChannelMockRecorder is the mock recorder for MockChannel.

func (*MockChannelMockRecorder) Close

func (mr *MockChannelMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockChannelMockRecorder) Flush

func (mr *MockChannelMockRecorder) Flush() *gomock.Call

Flush indicates an expected call of Flush.

func (*MockChannelMockRecorder) GetMeta

func (mr *MockChannelMockRecorder) GetMeta() *gomock.Call

GetMeta indicates an expected call of GetMeta.

func (*MockChannelMockRecorder) ID

ID indicates an expected call of ID.

func (*MockChannelMockRecorder) LocalAddr

func (mr *MockChannelMockRecorder) LocalAddr() *gomock.Call

LocalAddr indicates an expected call of LocalAddr.

func (*MockChannelMockRecorder) Push

func (mr *MockChannelMockRecorder) Push(payload interface{}) *gomock.Call

Push indicates an expected call of Push.

func (*MockChannelMockRecorder) Read

func (mr *MockChannelMockRecorder) Read(b interface{}) *gomock.Call

Read indicates an expected call of Read.

func (*MockChannelMockRecorder) ReadFrame

func (mr *MockChannelMockRecorder) ReadFrame() *gomock.Call

ReadFrame indicates an expected call of ReadFrame.

func (*MockChannelMockRecorder) Readloop

func (mr *MockChannelMockRecorder) Readloop(lst interface{}) *gomock.Call

Readloop indicates an expected call of Readloop.

func (*MockChannelMockRecorder) RemoteAddr

func (mr *MockChannelMockRecorder) RemoteAddr() *gomock.Call

RemoteAddr indicates an expected call of RemoteAddr.

func (*MockChannelMockRecorder) SetDeadline

func (mr *MockChannelMockRecorder) SetDeadline(t interface{}) *gomock.Call

SetDeadline indicates an expected call of SetDeadline.

func (*MockChannelMockRecorder) SetReadDeadline

func (mr *MockChannelMockRecorder) SetReadDeadline(t interface{}) *gomock.Call

SetReadDeadline indicates an expected call of SetReadDeadline.

func (*MockChannelMockRecorder) SetReadwait

func (mr *MockChannelMockRecorder) SetReadwait(timeout interface{}) *gomock.Call

SetReadwait indicates an expected call of SetReadwait.

func (*MockChannelMockRecorder) SetWriteDeadline

func (mr *MockChannelMockRecorder) SetWriteDeadline(t interface{}) *gomock.Call

SetWriteDeadline indicates an expected call of SetWriteDeadline.

func (*MockChannelMockRecorder) SetWritewait

func (mr *MockChannelMockRecorder) SetWritewait(timeout interface{}) *gomock.Call

SetWritewait indicates an expected call of SetWritewait.

func (*MockChannelMockRecorder) Write

func (mr *MockChannelMockRecorder) Write(b interface{}) *gomock.Call

Write indicates an expected call of Write.

func (*MockChannelMockRecorder) WriteFrame

func (mr *MockChannelMockRecorder) WriteFrame(opcode, payload interface{}) *gomock.Call

WriteFrame indicates an expected call of WriteFrame.

type MockClient

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

MockClient is a mock of Client interface.

func NewMockClient

func NewMockClient(ctrl *gomock.Controller) *MockClient

NewMockClient creates a new mock instance.

func (*MockClient) Close

func (m *MockClient) Close()

Close mocks base method.

func (*MockClient) Connect

func (m *MockClient) Connect(addr string) error

Connect mocks base method.

func (*MockClient) EXPECT

func (m *MockClient) EXPECT() *MockClientMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockClient) GetMeta

func (m *MockClient) GetMeta() map[string]string

GetMeta mocks base method.

func (*MockClient) Read

func (m *MockClient) Read() (Frame, error)

Read mocks base method.

func (*MockClient) Send

func (m *MockClient) Send(payload []byte) error

Send mocks base method.

func (*MockClient) ServiceID

func (m *MockClient) ServiceID() string

ServiceID mocks base method.

func (*MockClient) ServiceName

func (m *MockClient) ServiceName() string

ServiceName mocks base method.

func (*MockClient) SetDialer

func (m *MockClient) SetDialer(dialer Dialer)

SetDialer mocks base method.

type MockClientMockRecorder

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

MockClientMockRecorder is the mock recorder for MockClient.

func (*MockClientMockRecorder) Close

func (mr *MockClientMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockClientMockRecorder) Connect

func (mr *MockClientMockRecorder) Connect(addr interface{}) *gomock.Call

Connect indicates an expected call of Connect.

func (*MockClientMockRecorder) GetMeta

func (mr *MockClientMockRecorder) GetMeta() *gomock.Call

GetMeta indicates an expected call of GetMeta.

func (*MockClientMockRecorder) Read

func (mr *MockClientMockRecorder) Read() *gomock.Call

Read indicates an expected call of Read.

func (*MockClientMockRecorder) Send

func (mr *MockClientMockRecorder) Send(payload interface{}) *gomock.Call

Send indicates an expected call of Send.

func (*MockClientMockRecorder) ServiceID

func (mr *MockClientMockRecorder) ServiceID() *gomock.Call

ServiceID indicates an expected call of ServiceID.

func (*MockClientMockRecorder) ServiceName

func (mr *MockClientMockRecorder) ServiceName() *gomock.Call

ServiceName indicates an expected call of ServiceName.

func (*MockClientMockRecorder) SetDialer

func (mr *MockClientMockRecorder) SetDialer(dialer interface{}) *gomock.Call

SetDialer indicates an expected call of SetDialer.

type MockConn

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

MockConn is a mock of Conn interface.

func NewMockConn

func NewMockConn(ctrl *gomock.Controller) *MockConn

NewMockConn creates a new mock instance.

func (*MockConn) Close

func (m *MockConn) Close() error

Close mocks base method.

func (*MockConn) EXPECT

func (m *MockConn) EXPECT() *MockConnMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockConn) Flush

func (m *MockConn) Flush() error

Flush mocks base method.

func (*MockConn) LocalAddr

func (m *MockConn) LocalAddr() net.Addr

LocalAddr mocks base method.

func (*MockConn) Read

func (m *MockConn) Read(b []byte) (int, error)

Read mocks base method.

func (*MockConn) ReadFrame

func (m *MockConn) ReadFrame() (Frame, error)

ReadFrame mocks base method.

func (*MockConn) RemoteAddr

func (m *MockConn) RemoteAddr() net.Addr

RemoteAddr mocks base method.

func (*MockConn) SetDeadline

func (m *MockConn) SetDeadline(t time.Time) error

SetDeadline mocks base method.

func (*MockConn) SetReadDeadline

func (m *MockConn) SetReadDeadline(t time.Time) error

SetReadDeadline mocks base method.

func (*MockConn) SetWriteDeadline

func (m *MockConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline mocks base method.

func (*MockConn) Write

func (m *MockConn) Write(b []byte) (int, error)

Write mocks base method.

func (*MockConn) WriteFrame

func (m *MockConn) WriteFrame(opcode OpCode, payload []byte) error

WriteFrame mocks base method.

type MockConnMockRecorder

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

MockConnMockRecorder is the mock recorder for MockConn.

func (*MockConnMockRecorder) Close

func (mr *MockConnMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockConnMockRecorder) Flush

func (mr *MockConnMockRecorder) Flush() *gomock.Call

Flush indicates an expected call of Flush.

func (*MockConnMockRecorder) LocalAddr

func (mr *MockConnMockRecorder) LocalAddr() *gomock.Call

LocalAddr indicates an expected call of LocalAddr.

func (*MockConnMockRecorder) Read

func (mr *MockConnMockRecorder) Read(b interface{}) *gomock.Call

Read indicates an expected call of Read.

func (*MockConnMockRecorder) ReadFrame

func (mr *MockConnMockRecorder) ReadFrame() *gomock.Call

ReadFrame indicates an expected call of ReadFrame.

func (*MockConnMockRecorder) RemoteAddr

func (mr *MockConnMockRecorder) RemoteAddr() *gomock.Call

RemoteAddr indicates an expected call of RemoteAddr.

func (*MockConnMockRecorder) SetDeadline

func (mr *MockConnMockRecorder) SetDeadline(t interface{}) *gomock.Call

SetDeadline indicates an expected call of SetDeadline.

func (*MockConnMockRecorder) SetReadDeadline

func (mr *MockConnMockRecorder) SetReadDeadline(t interface{}) *gomock.Call

SetReadDeadline indicates an expected call of SetReadDeadline.

func (*MockConnMockRecorder) SetWriteDeadline

func (mr *MockConnMockRecorder) SetWriteDeadline(t interface{}) *gomock.Call

SetWriteDeadline indicates an expected call of SetWriteDeadline.

func (*MockConnMockRecorder) Write

func (mr *MockConnMockRecorder) Write(b interface{}) *gomock.Call

Write indicates an expected call of Write.

func (*MockConnMockRecorder) WriteFrame

func (mr *MockConnMockRecorder) WriteFrame(opcode, payload interface{}) *gomock.Call

WriteFrame indicates an expected call of WriteFrame.

type MockDialer

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

MockDialer is a mock of Dialer interface.

func NewMockDialer

func NewMockDialer(ctrl *gomock.Controller) *MockDialer

NewMockDialer creates a new mock instance.

func (*MockDialer) DialAndHandshake

func (m *MockDialer) DialAndHandshake(ctx DialerContext) (net.Conn, error)

DialAndHandshake mocks base method.

func (*MockDialer) EXPECT

func (m *MockDialer) EXPECT() *MockDialerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

type MockDialerMockRecorder

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

MockDialerMockRecorder is the mock recorder for MockDialer.

func (*MockDialerMockRecorder) DialAndHandshake

func (mr *MockDialerMockRecorder) DialAndHandshake(ctx interface{}) *gomock.Call

DialAndHandshake indicates an expected call of DialAndHandshake.

type MockDispatcher

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

MockDispatcher is a mock of Dispatcher interface.

func NewMockDispatcher

func NewMockDispatcher(ctrl *gomock.Controller) *MockDispatcher

NewMockDispatcher creates a new mock instance.

func (*MockDispatcher) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockDispatcher) Push

func (m *MockDispatcher) Push(gateway string, channels []string, p *pkt.LogicPkt) error

Push mocks base method.

type MockDispatcherMockRecorder

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

MockDispatcherMockRecorder is the mock recorder for MockDispatcher.

func (*MockDispatcherMockRecorder) Push

func (mr *MockDispatcherMockRecorder) Push(gateway, channels, p interface{}) *gomock.Call

Push indicates an expected call of Push.

type MockFrame

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

MockFrame is a mock of Frame interface.

func NewMockFrame

func NewMockFrame(ctrl *gomock.Controller) *MockFrame

NewMockFrame creates a new mock instance.

func (*MockFrame) EXPECT

func (m *MockFrame) EXPECT() *MockFrameMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockFrame) GetOpCode

func (m *MockFrame) GetOpCode() OpCode

GetOpCode mocks base method.

func (*MockFrame) GetPayload

func (m *MockFrame) GetPayload() []byte

GetPayload mocks base method.

func (*MockFrame) SetOpCode

func (m *MockFrame) SetOpCode(opcode OpCode)

SetOpCode mocks base method.

func (*MockFrame) SetPayload

func (m *MockFrame) SetPayload(payload []byte)

SetPayload mocks base method.

type MockFrameMockRecorder

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

MockFrameMockRecorder is the mock recorder for MockFrame.

func (*MockFrameMockRecorder) GetOpCode

func (mr *MockFrameMockRecorder) GetOpCode() *gomock.Call

GetOpCode indicates an expected call of GetOpCode.

func (*MockFrameMockRecorder) GetPayload

func (mr *MockFrameMockRecorder) GetPayload() *gomock.Call

GetPayload indicates an expected call of GetPayload.

func (*MockFrameMockRecorder) SetOpCode

func (mr *MockFrameMockRecorder) SetOpCode(opcode interface{}) *gomock.Call

SetOpCode indicates an expected call of SetOpCode.

func (*MockFrameMockRecorder) SetPayload

func (mr *MockFrameMockRecorder) SetPayload(payload interface{}) *gomock.Call

SetPayload indicates an expected call of SetPayload.

type MockMessageListener

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

MockMessageListener is a mock of MessageListener interface.

func NewMockMessageListener

func NewMockMessageListener(ctrl *gomock.Controller) *MockMessageListener

NewMockMessageListener creates a new mock instance.

func (*MockMessageListener) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockMessageListener) Receive

func (m *MockMessageListener) Receive(agent Agent, payload []byte)

Receive mocks base method.

type MockMessageListenerMockRecorder

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

MockMessageListenerMockRecorder is the mock recorder for MockMessageListener.

func (*MockMessageListenerMockRecorder) Receive

func (mr *MockMessageListenerMockRecorder) Receive(agent, payload interface{}) *gomock.Call

Receive indicates an expected call of Receive.

type MockServer

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

MockServer is a mock of Server interface.

func NewMockServer

func NewMockServer(ctrl *gomock.Controller) *MockServer

NewMockServer creates a new mock instance.

func (*MockServer) DialURL

func (m *MockServer) DialURL() string

DialURL mocks base method.

func (*MockServer) EXPECT

func (m *MockServer) EXPECT() *MockServerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockServer) GetMeta

func (m *MockServer) GetMeta() map[string]string

GetMeta mocks base method.

func (*MockServer) GetNamespace

func (m *MockServer) GetNamespace() string

GetNamespace mocks base method.

func (*MockServer) GetProtocol

func (m *MockServer) GetProtocol() string

GetProtocol mocks base method.

func (*MockServer) GetTags

func (m *MockServer) GetTags() []string

GetTags mocks base method.

func (*MockServer) PublicAddress

func (m *MockServer) PublicAddress() string

PublicAddress mocks base method.

func (*MockServer) PublicPort

func (m *MockServer) PublicPort() uint16

PublicPort mocks base method.

func (*MockServer) Push

func (m *MockServer) Push(channelID string, payload []byte) error

Push mocks base method.

func (*MockServer) ServiceID

func (m *MockServer) ServiceID() string

ServiceID mocks base method.

func (*MockServer) ServiceName

func (m *MockServer) ServiceName() string

ServiceName mocks base method.

func (*MockServer) SetAcceptor

func (m *MockServer) SetAcceptor(acceptor Acceptor)

SetAcceptor mocks base method.

func (*MockServer) SetChannelMap

func (m *MockServer) SetChannelMap(channelMap ChannelMap)

SetChannelMap mocks base method.

func (*MockServer) SetMessageListener

func (m *MockServer) SetMessageListener(messageListener MessageListener)

SetMessageListener mocks base method.

func (*MockServer) SetReadwait

func (m *MockServer) SetReadwait(readwait time.Duration)

SetReadwait mocks base method.

func (*MockServer) SetStateListener

func (m *MockServer) SetStateListener(stateListener StateListener)

SetStateListener mocks base method.

func (*MockServer) Shutdown

func (m *MockServer) Shutdown(ctx context.Context) error

Shutdown mocks base method.

func (*MockServer) Start

func (m *MockServer) Start() error

Start mocks base method.

func (*MockServer) String

func (m *MockServer) String() string

String mocks base method.

type MockServerMockRecorder

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

MockServerMockRecorder is the mock recorder for MockServer.

func (*MockServerMockRecorder) DialURL

func (mr *MockServerMockRecorder) DialURL() *gomock.Call

DialURL indicates an expected call of DialURL.

func (*MockServerMockRecorder) GetMeta

func (mr *MockServerMockRecorder) GetMeta() *gomock.Call

GetMeta indicates an expected call of GetMeta.

func (*MockServerMockRecorder) GetNamespace

func (mr *MockServerMockRecorder) GetNamespace() *gomock.Call

GetNamespace indicates an expected call of GetNamespace.

func (*MockServerMockRecorder) GetProtocol

func (mr *MockServerMockRecorder) GetProtocol() *gomock.Call

GetProtocol indicates an expected call of GetProtocol.

func (*MockServerMockRecorder) GetTags

func (mr *MockServerMockRecorder) GetTags() *gomock.Call

GetTags indicates an expected call of GetTags.

func (*MockServerMockRecorder) PublicAddress

func (mr *MockServerMockRecorder) PublicAddress() *gomock.Call

PublicAddress indicates an expected call of PublicAddress.

func (*MockServerMockRecorder) PublicPort

func (mr *MockServerMockRecorder) PublicPort() *gomock.Call

PublicPort indicates an expected call of PublicPort.

func (*MockServerMockRecorder) Push

func (mr *MockServerMockRecorder) Push(channelID, payload interface{}) *gomock.Call

Push indicates an expected call of Push.

func (*MockServerMockRecorder) ServiceID

func (mr *MockServerMockRecorder) ServiceID() *gomock.Call

ServiceID indicates an expected call of ServiceID.

func (*MockServerMockRecorder) ServiceName

func (mr *MockServerMockRecorder) ServiceName() *gomock.Call

ServiceName indicates an expected call of ServiceName.

func (*MockServerMockRecorder) SetAcceptor

func (mr *MockServerMockRecorder) SetAcceptor(acceptor interface{}) *gomock.Call

SetAcceptor indicates an expected call of SetAcceptor.

func (*MockServerMockRecorder) SetChannelMap

func (mr *MockServerMockRecorder) SetChannelMap(channelMap interface{}) *gomock.Call

SetChannelMap indicates an expected call of SetChannelMap.

func (*MockServerMockRecorder) SetMessageListener

func (mr *MockServerMockRecorder) SetMessageListener(messageListener interface{}) *gomock.Call

SetMessageListener indicates an expected call of SetMessageListener.

func (*MockServerMockRecorder) SetReadwait

func (mr *MockServerMockRecorder) SetReadwait(readwait interface{}) *gomock.Call

SetReadwait indicates an expected call of SetReadwait.

func (*MockServerMockRecorder) SetStateListener

func (mr *MockServerMockRecorder) SetStateListener(stateListener interface{}) *gomock.Call

SetStateListener indicates an expected call of SetStateListener.

func (*MockServerMockRecorder) Shutdown

func (mr *MockServerMockRecorder) Shutdown(ctx interface{}) *gomock.Call

Shutdown indicates an expected call of Shutdown.

func (*MockServerMockRecorder) Start

func (mr *MockServerMockRecorder) Start() *gomock.Call

Start indicates an expected call of Start.

func (*MockServerMockRecorder) String

func (mr *MockServerMockRecorder) String() *gomock.Call

String indicates an expected call of String.

type MockService

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

MockService is a mock of Service interface.

func NewMockService

func NewMockService(ctrl *gomock.Controller) *MockService

NewMockService creates a new mock instance.

func (*MockService) EXPECT

func (m *MockService) EXPECT() *MockServiceMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockService) GetMeta

func (m *MockService) GetMeta() map[string]string

GetMeta mocks base method.

func (*MockService) ServiceID

func (m *MockService) ServiceID() string

ServiceID mocks base method.

func (*MockService) ServiceName

func (m *MockService) ServiceName() string

ServiceName mocks base method.

type MockServiceMockRecorder

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

MockServiceMockRecorder is the mock recorder for MockService.

func (*MockServiceMockRecorder) GetMeta

func (mr *MockServiceMockRecorder) GetMeta() *gomock.Call

GetMeta indicates an expected call of GetMeta.

func (*MockServiceMockRecorder) ServiceID

func (mr *MockServiceMockRecorder) ServiceID() *gomock.Call

ServiceID indicates an expected call of ServiceID.

func (*MockServiceMockRecorder) ServiceName

func (mr *MockServiceMockRecorder) ServiceName() *gomock.Call

ServiceName indicates an expected call of ServiceName.

type MockServiceRegistration

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

MockServiceRegistration is a mock of ServiceRegistration interface.

func NewMockServiceRegistration

func NewMockServiceRegistration(ctrl *gomock.Controller) *MockServiceRegistration

NewMockServiceRegistration creates a new mock instance.

func (*MockServiceRegistration) DialURL

func (m *MockServiceRegistration) DialURL() string

DialURL mocks base method.

func (*MockServiceRegistration) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockServiceRegistration) GetMeta

func (m *MockServiceRegistration) GetMeta() map[string]string

GetMeta mocks base method.

func (*MockServiceRegistration) GetNamespace

func (m *MockServiceRegistration) GetNamespace() string

GetNamespace mocks base method.

func (*MockServiceRegistration) GetProtocol

func (m *MockServiceRegistration) GetProtocol() string

GetProtocol mocks base method.

func (*MockServiceRegistration) GetTags

func (m *MockServiceRegistration) GetTags() []string

GetTags mocks base method.

func (*MockServiceRegistration) PublicAddress

func (m *MockServiceRegistration) PublicAddress() string

PublicAddress mocks base method.

func (*MockServiceRegistration) PublicPort

func (m *MockServiceRegistration) PublicPort() uint16

PublicPort mocks base method.

func (*MockServiceRegistration) ServiceID

func (m *MockServiceRegistration) ServiceID() string

ServiceID mocks base method.

func (*MockServiceRegistration) ServiceName

func (m *MockServiceRegistration) ServiceName() string

ServiceName mocks base method.

func (*MockServiceRegistration) String

func (m *MockServiceRegistration) String() string

String mocks base method.

type MockServiceRegistrationMockRecorder

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

MockServiceRegistrationMockRecorder is the mock recorder for MockServiceRegistration.

func (*MockServiceRegistrationMockRecorder) DialURL

DialURL indicates an expected call of DialURL.

func (*MockServiceRegistrationMockRecorder) GetMeta

GetMeta indicates an expected call of GetMeta.

func (*MockServiceRegistrationMockRecorder) GetNamespace

func (mr *MockServiceRegistrationMockRecorder) GetNamespace() *gomock.Call

GetNamespace indicates an expected call of GetNamespace.

func (*MockServiceRegistrationMockRecorder) GetProtocol

func (mr *MockServiceRegistrationMockRecorder) GetProtocol() *gomock.Call

GetProtocol indicates an expected call of GetProtocol.

func (*MockServiceRegistrationMockRecorder) GetTags

GetTags indicates an expected call of GetTags.

func (*MockServiceRegistrationMockRecorder) PublicAddress

func (mr *MockServiceRegistrationMockRecorder) PublicAddress() *gomock.Call

PublicAddress indicates an expected call of PublicAddress.

func (*MockServiceRegistrationMockRecorder) PublicPort

PublicPort indicates an expected call of PublicPort.

func (*MockServiceRegistrationMockRecorder) ServiceID

ServiceID indicates an expected call of ServiceID.

func (*MockServiceRegistrationMockRecorder) ServiceName

func (mr *MockServiceRegistrationMockRecorder) ServiceName() *gomock.Call

ServiceName indicates an expected call of ServiceName.

func (*MockServiceRegistrationMockRecorder) String

String indicates an expected call of String.

type MockSessionStorage

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

MockSessionStorage is a mock of SessionStorage interface.

func NewMockSessionStorage

func NewMockSessionStorage(ctrl *gomock.Controller) *MockSessionStorage

NewMockSessionStorage creates a new mock instance.

func (*MockSessionStorage) Add

func (m *MockSessionStorage) Add(session *pkt.Session) error

Add mocks base method.

func (*MockSessionStorage) Delete

func (m *MockSessionStorage) Delete(account, channelID string) error

Delete mocks base method.

func (*MockSessionStorage) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSessionStorage) Get

func (m *MockSessionStorage) Get(channelID string) (*pkt.Session, error)

Get mocks base method.

func (*MockSessionStorage) GetLocation

func (m *MockSessionStorage) GetLocation(account, device string) (*Location, error)

GetLocation mocks base method.

func (*MockSessionStorage) GetLocations

func (m *MockSessionStorage) GetLocations(account ...string) ([]*Location, error)

GetLocations mocks base method.

type MockSessionStorageMockRecorder

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

MockSessionStorageMockRecorder is the mock recorder for MockSessionStorage.

func (*MockSessionStorageMockRecorder) Add

func (mr *MockSessionStorageMockRecorder) Add(session interface{}) *gomock.Call

Add indicates an expected call of Add.

func (*MockSessionStorageMockRecorder) Delete

func (mr *MockSessionStorageMockRecorder) Delete(account, channelID interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockSessionStorageMockRecorder) Get

func (mr *MockSessionStorageMockRecorder) Get(channelID interface{}) *gomock.Call

Get indicates an expected call of Get.

func (*MockSessionStorageMockRecorder) GetLocation

func (mr *MockSessionStorageMockRecorder) GetLocation(account, device interface{}) *gomock.Call

GetLocation indicates an expected call of GetLocation.

func (*MockSessionStorageMockRecorder) GetLocations

func (mr *MockSessionStorageMockRecorder) GetLocations(account ...interface{}) *gomock.Call

GetLocations indicates an expected call of GetLocations.

type MockStateListener

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

MockStateListener is a mock of StateListener interface.

func NewMockStateListener

func NewMockStateListener(ctrl *gomock.Controller) *MockStateListener

NewMockStateListener creates a new mock instance.

func (*MockStateListener) Disconnect

func (m *MockStateListener) Disconnect(channelID string) error

Disconnect mocks base method.

func (*MockStateListener) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

type MockStateListenerMockRecorder

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

MockStateListenerMockRecorder is the mock recorder for MockStateListener.

func (*MockStateListenerMockRecorder) Disconnect

func (mr *MockStateListenerMockRecorder) Disconnect(channelID interface{}) *gomock.Call

Disconnect indicates an expected call of Disconnect.

type OpCode

type OpCode byte
const (
	OpContinuation OpCode = 0x0
	OpText         OpCode = 0x1
	OpBinary       OpCode = 0x2
	OpClose        OpCode = 0x8
	OpPing         OpCode = 0x9
	OpPong         OpCode = 0xa
)

type Router

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

func NewRouter

func NewRouter() *Router

func (*Router) Handle

func (r *Router) Handle(command string, handlers ...HandlerFunc)

Handle register a command handler

func (*Router) Serve

func (r *Router) Serve(packet *pkt.LogicPkt, dispacther Dispatcher,
	cache SessionStorage, session Session) error

func (*Router) Use

func (r *Router) Use(handlers ...HandlerFunc)

type Server

type Server interface {
	ServiceRegistration

	SetAcceptor(acceptor Acceptor)

	SetMessageListener(messageListener MessageListener)

	SetStateListener(stateListener StateListener)

	SetReadwait(readwait time.Duration)

	SetChannelMap(channelMap ChannelMap)

	// Start 用于在内部实现网络端口的监听和接收连接,
	// 并完成一个Channel的初始化过程。
	Start() error
	// Push消息到指定的Channel中,
	Push(channelID string, payload []byte) error
	// 服务下线,关闭连接
	Shutdown(ctx context.Context) error
}

适用于不同底层协议(tcp、websocket)的通用服务端接口

type ServerOption

type ServerOption func(*ServerOptions)

func WithConnectionGPool

func WithConnectionGPool(val int) ServerOption

func WithMessageGPool

func WithMessageGPool(val int) ServerOption

type ServerOptions

type ServerOptions struct {
	Loginwait       time.Duration
	Readwait        time.Duration
	Writewait       time.Duration
	MessageGPool    int
	ConnectionGPool int
}

type Service

type Service interface {
	ServiceID() string
	ServiceName() string
	GetMeta() map[string]string
}

基础服务的抽象接口

type ServiceRegistration

type ServiceRegistration interface {
	Service
	PublicAddress() string
	PublicPort() uint16
	DialURL() string
	GetTags() []string
	GetProtocol() string
	GetNamespace() string
	String() string
}

服务注册的抽象接口

type Session

type Session interface {
	GetChannelId() string
	GetGateId() string
	GetAccount() string
	GetRemoteIp() string
	GetApp() string
	GetTags() []string
}

Session read only

type SessionStorage

type SessionStorage interface {
	Add(session *pkt.Session) error
	Delete(account, channelID string) error
	Get(channelID string) (*pkt.Session, error)
	GetLocations(account ...string) ([]*Location, error)
	GetLocation(account, device string) (*Location, error)
}

type StateListener

type StateListener interface {
	// 连接断开回调
	Disconnect(channelID string) error
}

状态监听器

type Upgrader

type Upgrader interface {
	Name() string
	Upgrade(rawconn net.Conn, rd *bufio.Reader, wr *bufio.Writer) (Conn, error)
}

Jump to

Keyboard shortcuts

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