util

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BodyLenExceedLimit = errors.New("body length exceed limit")
View Source
var HeadBytesLengthFail = errors.New("head bytes fail")
View Source
var Logger = NewLogger()
View Source
var RouterNotFound = errors.New("router Not Found")
View Source
var TLSHandshakeUnFinish = errors.New("tls handshake un finish")
View Source
var WebsocketOpcodeFail = errors.New("websocket opcode fail")

Functions

func ArrayReduce added in v0.1.7

func ArrayReduce(data interface{}, callable iface.CarryFunc, initial interface{}) interface{}

ArrayReduce .

func MaxListenerBacklog

func MaxListenerBacklog() int

MaxListenerBacklog 获取Accept队列的最大值

func NewContext added in v0.1.7

func NewContext(request iface.IRequest) iface.IContext

NewContext .

func NewLogger

func NewLogger() *logrus.Logger

NewLogger 日志

func NewPipeline added in v0.1.7

func NewPipeline() iface.IPipeline

func SockaddrToTCPOrUnixAddr

func SockaddrToTCPOrUnixAddr(sa unix.Sockaddr) net.Addr

SockaddrToTCPOrUnixAddr 转成net.Addr,方便提取ip和port

Types

type Context added in v0.1.7

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

func (*Context) Get added in v0.1.7

func (c *Context) Get(key interface{}) interface{}

func (*Context) GetConnect added in v0.1.7

func (c *Context) GetConnect() iface.IConnect

func (*Context) GetMessage added in v0.1.7

func (c *Context) GetMessage() iface.IMessage

GetMessage 获取消息

func (*Context) GetRequest added in v0.1.7

func (c *Context) GetRequest() iface.IRequest

func (*Context) Set added in v0.1.7

func (c *Context) Set(key, value interface{})

type DataPacker

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

DataPacker 可以自行实现IPacker,可以按照自己的协议格式来处理

func NewDataPacker

func NewDataPacker() *DataPacker

func (*DataPacker) GetHeaderLength added in v0.1.3

func (d *DataPacker) GetHeaderLength() uint32

GetHeaderLength 获取头部长度

func (*DataPacker) Pack

func (d *DataPacker) Pack(msgID uint32, data []byte) ([]byte, error)

Pack 封包格式:data长度(4字节)msgID(4字节)data

func (*DataPacker) SetMaxBodyLength added in v0.0.8

func (d *DataPacker) SetMaxBodyLength(maxBodyLength uint32)

SetMaxBodyLength .

func (*DataPacker) UnPack

func (d *DataPacker) UnPack(bs []byte) (iface.IMessage, error)

UnPack 解包数据(传到这里的只有前8个字节),后续的data部分需要Read读取

type Message

type Message struct {
	MsgID       uint32 // 消息ID
	DataLen     uint32 // 消息长度
	Data        []byte // 消息
	IsWebSocket bool   // 是否为websocket协议
	Opcode      uint8  // 操作码
}

Message 收到数据的封装

func (*Message) Bytes

func (m *Message) Bytes() []byte

Bytes 获取Bytes

func (*Message) GetOpcode added in v0.1.5

func (m *Message) GetOpcode() uint8

GetOpcode 获取操作码,通过这个可以判断是否为websocket消息

func (*Message) ID

func (m *Message) ID() uint32

func (*Message) IsWebsocket added in v0.1.5

func (m *Message) IsWebsocket() bool

func (*Message) Len

func (m *Message) Len() int

Len 获取长度

func (*Message) SetData

func (m *Message) SetData(bytes []byte)

SetData 设置数据

func (*Message) String

func (m *Message) String() string

type Pipeline added in v0.1.7

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

func (*Pipeline) Carry added in v0.1.7

func (p *Pipeline) Carry() iface.CarryFunc

func (*Pipeline) Pipe added in v0.1.7

func (p *Pipeline) Pipe(pipe iface.IStage) iface.IPipeline

Pipe 单个管道

func (*Pipeline) Send added in v0.1.7

func (p *Pipeline) Send(passable interface{}) iface.IPipeline

Send 需要处理的数据

func (*Pipeline) Then added in v0.1.7

func (p *Pipeline) Then(destination iface.NextFunc) interface{}

Then 将最终的结果输出到 destination

func (*Pipeline) Through added in v0.1.7

func (p *Pipeline) Through(pipes []iface.IStage) iface.IPipeline

Through 一次增加多个管道

type Queue added in v0.0.4

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

func NewQueue added in v0.0.4

func NewQueue() *Queue

func (*Queue) Len added in v0.0.4

func (q *Queue) Len() int

Len 获取队列长度

func (*Queue) Pop added in v0.0.4

func (q *Queue) Pop() interface{}

Pop 弹

func (*Queue) Push added in v0.0.4

func (q *Queue) Push(item interface{}) int

Push 加

type Request

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

func NewRequest

func NewRequest(connect iface.IConnect, message iface.IMessage, connectMgr iface.IConnectManager) *Request

func (*Request) GetConnect

func (r *Request) GetConnect() iface.IConnect

GetConnect 获取连接

func (*Request) GetConnects added in v0.1.1

func (r *Request) GetConnects() []iface.IConnect

GetConnects 获取所有的connect

func (*Request) GetMessage

func (r *Request) GetMessage() iface.IMessage

GetMessage 获取消息

Jump to

Keyboard shortcuts

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