package server import ( "slowwildws/internal/config" "slowwildws/internal/constants" "time" ) type ServerOptions func(opt *serverOption) type serverOption struct { maxConnectionIdle time.Duration // 连接空闲超时时间 ack constants.AckType // ack类型 ackTimeout time.Duration // ack等待超时时间 concurrency int // 并发数 } func newServerOptions(conf config.Config, opts ...ServerOptions) serverOption { o := serverOption{ maxConnectionIdle: time.Duration(conf.DefaultMaxConnectionIdleTime) * time.Second, ackTimeout: time.Duration(conf.DefaultAckTimeout) * time.Second, concurrency: conf.DefaultConcurrency, } for _, opt := range opts { opt(&o) } return o } func WithServerAck(ack constants.AckType) ServerOptions { return func(opt *serverOption) { opt.ack = ack } } func WithServerMaxConnectionIdle(maxConnectionIdle time.Duration) ServerOptions { return func(opt *serverOption) { if maxConnectionIdle > 0 { opt.maxConnectionIdle = maxConnectionIdle } } }