nnet

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: Apache-2.0 Imports: 19 Imported by: 1

README

NNet 轻量级 TCP/WS/UDP 网络库

===

封装了

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	config.EngineConf // 引擎配置
	// contains filtered or unexported fields
}

Engine 引擎

func NewEngine

func NewEngine(conf config.EngineConf, opts ...RunOption) *Engine

func (*Engine) AddRoutes

func (ngin *Engine) AddRoutes(rs ...rt.Route)

func (*Engine) ConnManager

func (ngin *Engine) ConnManager() *conn.ConnManager

ConnManager returns connection manager

func (*Engine) DialTCP added in v1.1.4

func (ngin *Engine) DialTCP(addr string) (*conn.Connection, error)

DialTCP 连接服务器

func (*Engine) DialWebsocket added in v1.1.4

func (ngin *Engine) DialWebsocket(url string, conf config.WSClientFullConf, evtOpts ...WsEventOption) (*conn.Connection, error)

DialWebsocket websocket方式 连接服务器

func (*Engine) EventManager added in v1.1.4

func (ngin *Engine) EventManager() event.EventManager

EventManager returns EventManager.

func (*Engine) ListenSerial added in v1.0.0

func (ngin *Engine) ListenSerial(conf serial.Config) error

ListenSerial 监听串口消息

func (*Engine) ListenTCP

func (ngin *Engine) ListenTCP(conf config.TCPServerConf) error

func (*Engine) ListenWebsocket

func (ngin *Engine) ListenWebsocket(conf config.WSServerFullConf, serverOpts []WsServerOption, evtOpts ...WsEventOption) error

ListenWebsocket 开始监听Websocket

func (*Engine) Stop

func (ngin *Engine) Stop()

func (*Engine) Use

func (ngin *Engine) Use(middleware ...rt.Middleware)

type RunOption

type RunOption func(ngin *Engine)

RunOption defines the method to customize an Engine.

func WithMiddleware

func WithMiddleware(middleware ...rt.Middleware) RunOption

func WithNotFoundHandler

func WithNotFoundHandler(handler rt.Handler) RunOption

WithNotFoundHandler returns a RunOption with not found handler set to given handler.

func WithPackerBuilder

func WithPackerBuilder(fn packet.PackerBuilder) RunOption

WithPackerBuilder 设置 消息的封包/解包构造器

func WithRouter

func WithRouter(router rt.Router) RunOption

WithRouter 设置消息路由

func WithSendSize added in v1.2.8

func WithSendSize(sendSize int) RunOption

func WithSerializer

func WithSerializer(s ndef.Serializer) RunOption

WithSerializer 设置消息的 序列化/反序列化 方式

func WithTimerPrecision

func WithTimerPrecision(precision time.Duration) RunOption

WithTimerPrecision 设置Timer精度,需在 Start 或 Dial 之前执行 注:精度需大于1ms, 并且不能在运行时更改 默认精度是 time.Second

func WithWriteSize added in v1.2.8

func WithWriteSize(size int) RunOption

type WsEventOption added in v1.1.4

type WsEventOption func(conf config.WSEvent)

func WithCloseHandler added in v1.1.4

func WithCloseHandler(fn func(closeCode int, closeText string) error) WsEventOption

func WithPingHandler added in v1.1.4

func WithPingHandler(fn func(appData string)) WsEventOption

func WithPongHandler added in v1.1.4

func WithPongHandler(fn func(appData string)) WsEventOption

type WsServerOption added in v1.1.4

type WsServerOption func(conf config.WSServerFullConf)

func WithWSCheckOrigin added in v1.1.1

func WithWSCheckOrigin(fn func(*http.Request) bool) WsServerOption

Directories

Path Synopsis
protocol
serialize

Jump to

Keyboard shortcuts

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