You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
705 B
37 lines
705 B
2 years ago
|
package msggateway
|
||
2 years ago
|
|
||
|
import "time"
|
||
|
|
||
|
type Option func(opt *configs)
|
||
|
type configs struct {
|
||
|
//长连接监听端口
|
||
|
port int
|
||
|
//长连接允许最大链接数
|
||
2 years ago
|
maxConnNum int64
|
||
2 years ago
|
//连接握手超时时间
|
||
|
handshakeTimeout time.Duration
|
||
|
//允许消息最大长度
|
||
|
messageMaxMsgLength int
|
||
|
}
|
||
|
|
||
|
func WithPort(port int) Option {
|
||
|
return func(opt *configs) {
|
||
|
opt.port = port
|
||
|
}
|
||
|
}
|
||
2 years ago
|
func WithMaxConnNum(num int64) Option {
|
||
2 years ago
|
return func(opt *configs) {
|
||
|
opt.maxConnNum = num
|
||
|
}
|
||
|
}
|
||
|
func WithHandshakeTimeout(t time.Duration) Option {
|
||
|
return func(opt *configs) {
|
||
|
opt.handshakeTimeout = t
|
||
|
}
|
||
|
}
|
||
|
func WithMessageMaxMsgLength(length int) Option {
|
||
|
return func(opt *configs) {
|
||
|
opt.messageMaxMsgLength = length
|
||
|
}
|
||
|
}
|