go808

package module
v0.0.0-...-20b7a9e Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogLevel

func SetLogLevel(level Level) error

设置日志级别

Types

type CountdownTimer

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

倒计时器

func NewCountdownTimer

func NewCountdownTimer(seconds int64, callback func(string)) *CountdownTimer

创建倒计时器

func (*CountdownTimer) Remove

func (timer *CountdownTimer) Remove(key string)

删除计时

func (*CountdownTimer) SetExpiration

func (timer *CountdownTimer) SetExpiration(seconds int64)

设置过期时间

func (*CountdownTimer) Update

func (timer *CountdownTimer) Update(key string)

更新时间

type Level

type Level string

日志等级

var (
	PanicLevel Level = "panic"
	FatalLevel Level = "fatal"
	ErrorLevel Level = "error"
	WarnLevel  Level = "warn"
	InfoLevel  Level = "info"
	DebugLevel Level = "debug"
	TraceLevel Level = "trace"
)

type MessageHandler

type MessageHandler func(*Session, *protocol.Message)

type MultipartFile

type MultipartFile struct {
	IccID uint64
	MsgID protocol.MsgID
	Tag   uint32
	Sum   uint16
}

多分包文件

func (MultipartFile) IsFull

func (m MultipartFile) IsFull() bool

是否完整

func (MultipartFile) Merge

func (m MultipartFile) Merge() (io.ReadCloser, error)

合并文件

func (MultipartFile) Write

func (m MultipartFile) Write(seq uint16, data []byte) error

写入分包文件

type Options

type Options struct {
	Keepalive       int64
	AutoMergePacket bool
	CloseHandler    func(*Session)
	PrivateKey      *rsa.PrivateKey
}

服务器选项

type Protocol

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

func (Protocol) NewCodec

func (p Protocol) NewCodec(rw io.ReadWriter) (link.Codec, error)

创建编解码器

type ProtocolCodec

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

编解码器

func (*ProtocolCodec) Close

func (codec *ProtocolCodec) Close() error

关闭读写

func (*ProtocolCodec) GetPublicKey

func (codec *ProtocolCodec) GetPublicKey() *rsa.PublicKey

获取RSA公钥

func (*ProtocolCodec) Receive

func (codec *ProtocolCodec) Receive() (interface{}, error)

接收消息

func (*ProtocolCodec) Send

func (codec *ProtocolCodec) Send(msg interface{}) error

发送消息

func (*ProtocolCodec) SetPublicKey

func (codec *ProtocolCodec) SetPublicKey(publicKey *rsa.PublicKey)

设置RSA公钥

type Server

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

协议服务器

func NewServer

func NewServer(options Options) (*Server, error)

创建服务

func (*Server) AddHandler

func (server *Server) AddHandler(msgID protocol.MsgID, handler MessageHandler)

添加消息处理

func (*Server) Broadcast

func (server *Server) Broadcast(entity protocol.Entity) int

广播消息

func (*Server) GetPrivateKey

func (server *Server) GetPrivateKey() *rsa.PrivateKey

获取平台私钥

func (*Server) GetSession

func (server *Server) GetSession(id uint64) (*Session, bool)

获取Session

func (*Server) Run

func (server *Server) Run(network string, port int) error

运行服务

func (*Server) Stop

func (server *Server) Stop()

停止服务

type Session

type Session struct {
	UserData interface{}
	// contains filtered or unexported fields
}

终端会话

func (*Session) Close

func (session *Session) Close() error

关闭连接

func (*Session) GetPublicKey

func (session *Session) GetPublicKey() *rsa.PublicKey

获取RSA公钥

func (*Session) GetServer

func (session *Session) GetServer() *Server

获取服务实例

func (*Session) ID

func (session *Session) ID() uint64

获取ID

func (*Session) Reply

func (session *Session) Reply(msg *protocol.Message, result protocol.Result) (uint16, error)

回复消息

func (*Session) Request

func (session *Session) Request(entity protocol.Entity, cb func(answer *protocol.Message)) (uint16, error)

发起请求

func (*Session) Send

func (session *Session) Send(entity protocol.Entity) (uint16, error)

发送消息

func (*Session) SetPublicKey

func (session *Session) SetPublicKey(publicKey *rsa.PublicKey)

设置RSA公钥

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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