1 Star 0 Fork 0

jmesyan/impetus

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
options.go 1.72 KB
一键复制 编辑 原始数据 按行查看 历史
jmesyan 提交于 2020-12-12 22:03 . init
package pomelo
import (
"time"
)
type Option func(*Options)
type Options struct {
MaxConnNum int
MaxMsgLen uint32
HeartbeatTimeout time.Duration
// websocket
WSAddr string
HTTPTimeout time.Duration
CertFile string
KeyFile string
// tcp
TCPAddr string
}
func newOptions(opts...Option) *Options {
opt := &Options{
MaxConnNum: 20000,
MaxMsgLen: 4096,
HTTPTimeout: 10 * time.Second,
HeartbeatTimeout: 20 * time.Second,
}
for _,o := range opts {
o(opt)
}
return opt
}
// Max connections support. Default is 20000
func MaxConnNum(num int) Option {
return func(options *Options) {
options.MaxConnNum = num
}
}
// Max message length. If a message exceeds the limit, the connection sends a close message to the peer. Default is 4096
func MaxMsgLen(length uint32) Option {
return func(options *Options) {
options.MaxMsgLen = length
}
}
// Address of tcp server as "host:port"
func TCPAddr(addr string) Option {
return func(options *Options) {
options.TCPAddr = addr
}
}
// Address of websocket server as "host:port"
func WSAddr(addr string) Option {
return func(options *Options) {
options.WSAddr = addr
}
}
// Timeout for http handshake. Default is 10s
func HTTPTimeout(t time.Duration) Option {
return func(options *Options) {
options.HTTPTimeout = t
}
}
// Cert file for https
func CertFile(f string) Option {
return func(options *Options) {
options.CertFile = f
}
}
// Key file for https
func KeyFile(f string) Option {
return func(options *Options) {
options.KeyFile = f
}
}
// Heartbeat timeout. Default is 10s. Disconnect if after 2*t
func HeartbeatTimeout(t time.Duration) Option {
return func(options *Options) {
options.HeartbeatTimeout = t
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jmesyan/impetus.git
git@gitee.com:jmesyan/impetus.git
jmesyan
impetus
impetus
v1.0.3

搜索帮助