config

package
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: 3 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DevMode means development mode.
	DevMode = "dev"
	// TestMode means test mode.
	TestMode = "test"
	// ProductionMode means production mode.
	ProductionMode = "prod"
)
View Source
const (
	DefaultSendChannelSize  = 1 << 10
	DefaultWriteChannelSize = 1 << 10 << 10
)

Defaults

Variables

This section is empty.

Functions

This section is empty.

Types

type BackoffConf added in v1.1.4

type BackoffConf struct {
	// MinRecTime 最小重连时间间隔 默认2s
	MinRecTime time.Duration `json:",default=2s"`
	// MaxRecTime 最大重连时间间隔 默认60s
	MaxRecTime time.Duration `json:",default=60s"`
	// RecFactor 每次重连失败继续重连的时间间隔递增的乘数因子,递增到最大重连时间间隔为止
	RecFactor float64 `json:",default=1.5"`
}

BackoffConf 自动重连配置

type EngineConf

type EngineConf struct {
	// TaskTimerPrecision 全局任务的timer间隔
	TaskTimerPrecision time.Duration `json:",default=1s"`
	// Mode 运行模式
	Mode string `json:",default=dev,options=[dev,test,prod]"`
	// Name 引擎名称
	Name string `json:",default=NL,env=ENGINE_NAME"`
	// ReadDeadline 读数据超时时长,0为不超时
	ReadDeadline time.Duration `json:",default=0s"`
	// WriteDeadline 写数据超时时长,0为不超时
	WriteDeadline time.Duration `json:",default=0s"`
	// Deadline 读+写数据超时时长,0为不超时
	Deadline time.Duration `json:",default=0s"`
	// SendChannelSize
	SendChannelSize int `json:",default=1024"`
	// WriteChannelSize
	WriteChannelSize int `json:",default=1024"`
}

func (EngineConf) LogPrefix added in v0.7.0

func (c EngineConf) LogPrefix() string

func (EngineConf) ShallLogDebug added in v0.7.0

func (c EngineConf) ShallLogDebug() bool

ShallLogDebug 是否应该打印 Debug 级别的日志,打印的首要条件是 nlog 的打印级别为 debug

type TCPServerConf added in v0.7.0

type TCPServerConf struct {
	// Protocol 协议名
	// "tcp", "tcp4", "tcp6", "unix" or "unixpacket"
	// 若只想开启IPv4, 使用tcp4即可
	Protocol string `json:",default=tcp4,env=TCP_PROTOCOL"`
	// Addr 服务地址
	// 地址可直接使用hostname,但强烈不建议这样做,可能会同时监听多个本地IP
	// 如果端口号不填或端口号为0,例如:"127.0.0.1:" 或 ":0",服务端将选择随机可用端口
	Addr string `json:",default=0.0.0.0:9876,env=TCP_ADDR"`
}

type WSClientConf added in v1.1.4

type WSClientConf struct {
	// ReadLimit 单条消息支持的最大消息长度,默认 8MB
	ReadLimit int64 `json:",default=8192"`
	// WriteDeadline 写超时,默认5s
	WriteDeadline time.Duration `json:",default=5s"`
	// ReadDeadline 读超时,控制断线检测 默认60s
	ReadDeadline time.Duration `json:",default=60s"`
}

type WSClientFullConf added in v1.1.4

type WSClientFullConf struct {
	WSConf
	WSClientConf
	BackoffConf
	WSEvent `json:"-"`
}

WSClientFullConf 完整的客户端配置

type WSConf added in v1.1.4

type WSConf struct {
	// Addr 服务地址
	// 地址可直接使用hostname,但强烈不建议这样做,可能会同时监听多个本地IP
	// 如果端口号不填或端口号为0,例如:"127.0.0.1:" 或 ":0",服务端将选择随机可用端口
	Addr string `json:",default=0.0.0.0:9876,env=WS_ADDR"`
	// Path 监听路径 /WebsocketPath
	Path string `json:",default=/,env=WS_PATH"`
	// HandshakeTimeout 握手超时时间,默认0
	HandshakeTimeout time.Duration `json:",default=0"`
	// ReadBufferSize 读缓冲区大小
	ReadBufferSize int `json:",default=2048"`
	// WriteBufferSize 写缓冲区大小
	WriteBufferSize int `json:",default=2048"`
	// Compression 是否使用压缩协议
	Compression bool `json:",default=false"`
	// TLSCertificate  证书地址
	TLSCertificate string `json:",optional"`
	// TLS 证书key地址
	TLSKey string `json:",optional"`
}

func (WSConf) IsTLS added in v1.1.4

func (c WSConf) IsTLS() bool

type WSEvent added in v1.1.4

type WSEvent struct {
	// PingHandler Ping
	PingHandler func(appData string)
	// PongHandler Pong
	PongHandler func(appData string)
	// CloseHandler Close
	CloseHandler func(closeCode int, closeText string) error
}

type WSServerFullConf added in v1.1.2

type WSServerFullConf struct {
	WSConf
	WSEvent `json:"-"`
	// check origin
	CheckOrigin func(*http.Request) bool `json:"-"`
}

Jump to

Keyboard shortcuts

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